In the book Hibernate in Action and online examples, the following example occur on the topic of CompositeUserType.
The method nullSafeGet is as follows:
Code:
public Object nullSafeGet(...) throws ... {
if(resultSet.wasNull()) return null;
BigDecimal value = resultSet.getBigDecimal(names[0]);
...
return new MonetaryAmount(value, currency);
}
But the javadoc on jdk 1.5 states the following on the wasNull method:
Quote:
boolean java.sql.ResultSet.wasNull()
Reports whether the last column read had a value of SQL NULL. Note that you must first call one of the getter methods on a column to try to read its value and then call the method wasNull to see if the value read was SQL NULL.
And as you can see from the code, there has been no call to any of the getters prior to the wasNull() call.
The result, at least for me, was that the nullSafeGet method allways returned null!
The fix is ofcourse to move the line:
Code:
BigDecimal value = resultSet.getBigDecimal(names[0]);
above the line
Code:
if(resultSet.wasNull()) return null;
this does not generate an error even when the resultSet.wasNull is true.
This is not a bug in hibernate, but bad examples can be costly on the users.
Simen.