Ironic, I know...
I'm not sure if this should go in the main forum or in this forum, but since this class is only distributed with the annotations package, I've posted it here.
Since updating to the Annotations beta4 release, I am now getting a NullPointerException during session flush:
java.lang.NullPointerException
at org.hibernate.type.EnumType.nullSafeSet(EnumType.java:120)
at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:141)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
...
Here's the code for nullSafeSet(), beta4 release:
Code:
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
if (!guessed) guessType( st, index );
if (value == null) {
if (IS_TRACE_ENABLED) log.debug("Binding null to parameter: " + index);
st.setNull( index, sqlType );
}
boolean isOrdinal = isOrdinal(sqlType);
if (isOrdinal) {
int ordinal = ( (Enum) value ).ordinal();
if ( IS_TRACE_ENABLED ) {
log.debug("Binding '" + ordinal + "' to parameter: " + index);
}
st.setObject( index, new Integer(ordinal), sqlType );
}
else {
String enumString = ( (Enum) value ).name();
if ( IS_TRACE_ENABLED ) {
log.debug("Binding '" + enumString + "' to parameter: " + index);
}
st.setObject( index, enumString, sqlType );
}
}
With casual inspection, it is quite clear that this method is going to crash every time value is null. The source code for the beta3 version of method reveals that it previously handled null correctly, but the it has been completely rewritten in beta4.
Anyone else had this problem? I searched for "EnumType" and "nullsafeSet" in the issue tracker and could not find any matching issues. I'll try hacking my local copy of Hibernate and see if that clears it up.