Hi,
I defined a custom userType and I want to use it at the ID column using annotations, it seems hibernate 3 ignores the @Type annotation if it is set on an @Id field. It used to work on hibernate 2, is this intended? Thanks.
Kent
My custom user type:
public class PoolTradeEmptyUserType implements UserType {
public int[] sqlTypes() {
return new int[]{Types.CHAR};
}
public Class returnedClass() {
return com.nomura.fi.mbs.table.tba.PoolTradeEmptyUserType.class;
}
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y)
return true;
if (x == null || y == null)
return false;
else
return x.equals(y);
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
if (rs.wasNull()) {
return null;
} else {
String poolTradeNumber = rs.getString(names[0]);
if (poolTradeNumber == null)
return null;
if (poolTradeNumber.equals(" "))
return null;
else
return poolTradeNumber;
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.VARCHAR);
} else {
st.setString(index, (String) value);
}
}
public Object deepCopy(Object value) throws HibernateException {
return value;
}
public boolean isMutable() {
return false;
}
public Object replace(Object object, Object object1, Object object2) throws HibernateException {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Serializable disassemble(Object object) throws HibernateException {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public Object assemble(Serializable serializable, Object object) throws HibernateException {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public int hashCode(Object object) throws HibernateException {
return object.hashCode(); //To change body of implemented methods use File | Settings | File Templates.
}
}
My class using the userType, I included the xdoclet for hiberate 2 which worked perfectly:
/**
* @hibernate.class table="pooltrds" lazy="true"
* @hibernate.cache usage="transactional"
*/
@Entity
@Table(name = "pooltrds")
@TypeDefs( value = {
@TypeDef (name ="poolUserType", typeClass= PoolTradeEmptyUserType.class)
}
)
public class PoolTrade implements Serializable {
private String poolTradeNum;
private String tbaXrefNum;
public PoolTrade() {
}
/**
* @hibernate.id generator-class="assigned" column="pool_trdnum" type="com.nomura.fi.mbs.table.tba.PoolTradeEmptyUserType"
*/
@Id(generate = GeneratorType.NONE)
@Column(name = "pool_trdnum")
@Type(type = "poolUserType")
public String getPoolTradeNum() {
return poolTradeNum;
}
public void setPoolTradeNum(String poolTradeNum) {
this.poolTradeNum = poolTradeNum;
}
/**
* @hibernate.property column="tba_xref_num"
*/
@Column(name = "tba_xref_num")
public String getTbaXrefNum() {
return tbaXrefNum;
}
public void setTbaXrefNum(String tbaXrefNum) {
this.tbaXrefNum = tbaXrefNum;
}
}
|