I have a class that cannot be cached in hibernate's 2nd level cache using EHCache. It works when i leave out 1 specific property from the mapping. This property is a char(1) mapped to a boolean in java through a custom UserType. However, another property is a enum between 2 chars mapped to a boolean in the same way, and the cache works with this property included.
I should mention that this class works through hibernate as expected with read/write etc, its only the cache that doesnt work.
I have tried upgrading to hibernate 3.2.4.SP1 and the EHCache that comes with it, but this had no effect. I'm using mysql 3.23.58.
Any help is appreciated.
/Michael
The mapping class of the enum to bool mapping. The char to bool is identical just containing different values for the char.
Code:
public class EnumActivationBooleanStatus implements UserType {
private int[] SQL_TYPES = {Types.VARCHAR};
public int[] sqlTypes() {
return SQL_TYPES;
}
public Class returnedClass() {
return Boolean.class;
}
public boolean equals(Object x, Object y) throws HibernateException {
return x.equals(y);
}
public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
if(rs.wasNull()) {
return Boolean.FALSE;
}
String status = rs.getString(names[0]);
return Boolean.valueOf("a".equals(status));
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
if(value == null) {
st.setNull(index, Types.VARCHAR);
} else {
st.setString(index, (((Boolean)value)?"a":"na"));
}
}
public Object deepCopy(Object value) throws HibernateException {
return value;
}
public boolean isMutable() {
return false;
}
public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}
public Object assemble(Serializable cached, Object owner) throws HibernateException {
return cached;
}
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return original;
}
}