Thread:
 Error in default values implementation 
 MattFlower   06 Aug 2006, 01:43 
 Re: Error in default values implementation 
 levmatta   04 Sep 2006, 14:11 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: MattFlower (06 Aug 2006, 01:43) Replies: 1, Views: 27648
Subject: Error in default values implementation
This is a nice, simple implementation, but I think there is at least one
error in the implementation of default values.

As is, nullSafeGet won't use the default value because of the check on
rs.wasNull().  If we intend to use the default value there, I believe
that (name == null) would be a better check.

Another decent question would be whether nullSafeSet should be
explicitly setting the default value or the null value.  If it should be
setting the default value, there is no handling of such.

For now, I replaced my nullSafeGet as follows:

    public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
            throws HibernateException, SQLException {
        String value = rs.getString( names[0] );
        if (value==null) {
            value = getDefaultValue();
            if (value==null){ //no default value
                return null;
            }
        }
        String name = getNameFromValue(enumClass, value);
        Object res = name == null ? null : Enum.valueOf(enumClass, name);

        return res;
    }
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]