-->
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.  [ 3 posts ] 
Author Message
 Post subject: @Type not working for ID columns
PostPosted: Thu Apr 14, 2005 11:11 am 
Newbie

Joined: Thu Apr 14, 2005 11:02 am
Posts: 1
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;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 12:11 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Open a Jira issue in HibernateExt/annotations

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 2:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
now fixed.

_________________
Emmanuel


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

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.