-->
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: Getting ClassCastException from hibernate composite id
PostPosted: Tue Oct 27, 2009 12:29 am 
Newbie

Joined: Tue Oct 27, 2009 12:07 am
Posts: 1
Hi,

I have a table with primary composite key -

<hibernate-mapping>
<class name="com.yahoo.sm3.metadata.dao.data.SegmentsVersions" table="segments_versions" catalog="metadata">
<composite-id name="id" class="com.yahoo.sm3.metadata.dao.data.SegmentsVersionsId">
<key-property name="segmentid" type="long">
<column name="segmentid" />
</key-property>
<key-property name="versionnumber" type="int">
<column name="versionnumber" />
</key-property>
</composite-id>
...
</hibernate-mapping>

POJO Class for the component SegmentsVersionsId is as follows -

public class SegmentsVersionsId implements Serializable {
static final long serialVersionUID = 123123;

private long segmentid;
private int versionnumber;

public SegmentsVersionsId() {
}

public SegmentsVersionsId(long segmentid, int versionnumber) {
this.segmentid = segmentid;
this.versionnumber = versionnumber;
}

public long getSegmentid() {
return this.segmentid;
}

public void setSegmentid(long segmentid) {
this.segmentid = segmentid;
}

public int getVersionnumber() {
return this.versionnumber;
}

public void setVersionnumber(int versionnumber) {
this.versionnumber = versionnumber;
}

public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof SegmentsVersionsId))
return false;
SegmentsVersionsId castOther = (SegmentsVersionsId) other;

return (this.getSegmentid() == castOther.getSegmentid())
&& (this.getVersionnumber() == castOther.getVersionnumber());
}

public int hashCode() {
int result = 17;

result = 37 * result + (int) this.getSegmentid();
result = 37 * result + this.getVersionnumber();
return result;
}

}

I am using hibernate-3.3.2 and Spring-2.5.6 - getting the following error -

Caused by: java.lang.ClassCastException: com.yahoo.sm3.metadata.dao.data.SegmentsVersionsId
at com.yahoo.sm3.metadata.dao.hibernate.HibernateSegmentsVersionsDAO.saveSegmentsVersions(HibernateSegmentsVersionsDAO.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.orm.hibernate3.HibernateInterceptor.invoke(HibernateInterceptor.java:111)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy2.saveSegmentsVersions(Unknown Source)
at com.yahoo.sm3.metadata.SegmentsVersionsApp.saveSegmentsVersions(SegmentsVersionsApp.java:27)
... 1 more

i used hbm2java to get the java codes for POJO and hbm files. I think everything looks okay to me whatever i read in the documentations. But still getting this weird error all the day today. I am hoping somebody can help find the cause.

Thanks


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.