-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Custom UserType mapped property makes class not cacheable
PostPosted: Mon Jul 02, 2007 11:39 am 
Newbie

Joined: Mon Jul 02, 2007 11:20 am
Posts: 1
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;
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.