Hi
I was trying to use the <one-to-many> element and i was not quite able to get thru a java.lang.ClassCastException.
I have three tables USR, ROLE AND USR_ROLE. The relationship between USR and ROLE is m:m and hence i have created a association table USR_ROLE.
The primary keys for these tables have been defined as...
USR(USR_NO)
ROLE ( ROLE_ID)
USR_ROLE(USR_NO,ROLE_ID)
I created a POJO for each of these tables and i am trying to map the Usr class to UsrRole Class initially. (1:m)
This is my Usr.hbm.xml
Code:
<hibernate-mapping>
<class name="au.com.wow.sp.dao.hibernate.Usr"
table="USR">
<id name="usrNo" column="USR_NO">
<generator class="sequence">
<param name="sequence">S_USER</param>
</generator>
</id>
<!-- other properties -->
<set name="userRoleSet" table="USR_ROLE">
<key column="USR_NO"/>
<one-to-many class="au.com.wow.sp.dao.hibernate.UsrRole" />
</set>
</class>
</hibernate-mapping>
The equivalent POJO class has the definition and the setters/getters of the set userRoleSet.
This is my UsrRole.hbm.xml
Code:
<hibernate-mapping>
<class name="au.com.wow.sp.dao.hibernate.UsrRole" table="USR_ROLE">
<composite-id>
<key-property name="usrNo" column="USR_NO" />
<key-property name="roleId" column="ROLE_ID" />
</composite-id>
<!-- other properties -->
</class>
</hibernate-mapping>
The equivalent POJO class has the required attributes defined.
While i try to retrieve the values inside the userRoleSet,i get the following exception
java.lang.ClassCastException: au.com.wow.sp.dao.hibernate.UsrRole
Would there be a problem with the <composite-id> element in my code?
Can someone pls help me in getting through this?
Thanks
Karthik