日期:2014-05-16 浏览次数:20522 次
<class name="com.test.A" table="T_BASE_SETTINGS"> <composite-id name="id" class="com.test.B"> <key-property name="name" type="com.text.util.DefaultStringType"> <column name="NAME"/> </key-property> <key-property name="value" type="com.text.util.DefaultStringType"> <column name="VALUE"/> </key-property> </composite-id> </class> <query name="GET_SURCHARGE_VALUE"> FROM com.test.A a WHERE a.id.name =? and a.id.value=? </query>
public class DefaultStringType implements UserType { private static final String blankChart = ""; private static final int[] TYPES = new int[]{Types.VARCHAR}; /* (non-Javadoc) * @see org.hibernate.usertype.UserType#assemble(java.io.Serializable, java.lang.Object) */ public Object assemble(Serializable cached, Object owner) throws HibernateException { return null; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object) */ public Object deepCopy(Object value) throws HibernateException { String copy = new String(value.toString()); return copy; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#disassemble(java.lang.Object) */ public Serializable disassemble(Object value) throws HibernateException { return null; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#equals(java.lang.Object, java.lang.Object) */ public boolean equals(Object x, Object y) throws HibernateException { if (x == y) return true; if (x == null) return false; return x.equals(y); } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#hashCode(java.lang.Object) */ public int hashCode(Object x) throws HibernateException { return new HashCodeBuilder().append(x).toHashCode(); } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#isMutable() */ public boolean isMutable() { return false; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object) */ public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { String value = (String) Hibernate.STRING.nullSafeGet(rs, names[0]); return value == null ? "" : value; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int) */ public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { if (value.equals(blankChart)) { Hibernate.STRING.nullSafeSet(st, null, index); } else { Hibernate.STRING.nullSafeSet(st, value, index); } } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#replace(java.lang.Object, java.lang.Object, java.lang.Object) */ public Object replace(Object original, Object target, Object owner) throws HibernateException { return original; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#returnedClass() */ public Class returnedClass() { return String.class; } /* (non-Javadoc) * @see org.hibernate.usertype.UserType#sqlTypes() */ public int[] sqlTypes() { return TYPES; } }