I've made some changes to the nullSafeSet function. It's possible that
your association is not required, then you have to store a null value in
the database.
/**
* @see
net.sf.hibernate.UserType#nullSafeSet(java.sql.PreparedStatement,
java.lang.Object, int)
*/
public void nullSafeSet(PreparedStatement st, Object value, int
index) throws HibernateException, SQLException {
// make sure the received value is of the right type
if ((value != null) &&
!returnedClass().isAssignableFrom(value.getClass())) {
throw new IllegalArgumentException("Received value is not a [" +
returnedClass().getName() + "] but [" +
value.getClass() + "]");
}
if (value == null) {
st.setNull(index, getNullableType().sqlType());
} else {
// convert the enum into its persistence format
Serializable enumCode = ((PersistentEnum) value).getEnumCode();
// set the value into the resultset
st.setObject(index, enumCode, getNullableType().sqlType());
}
} |