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;
} |