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
|