-->
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.  [ 2 posts ] 
Author Message
 Post subject: ClassCastException with <one-to-many>
PostPosted: Sun Aug 27, 2006 9:16 am 
Newbie

Joined: Sun Aug 27, 2006 8:36 am
Posts: 1
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 27, 2006 3:03 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 12:09 pm
Posts: 48
Location: Slovakia (SK), Košice (KE)
maybe one of this will help:

instead
<set name="userRoleSet" table="USR_ROLE">
try
<set name="userRoleSet">


or

instead
<key-property name="usrNo" column="USR_NO" />
try
<key-many-to-one name="usrNo" column="USR_NO" class="au.com.wow.sp.dao.hibernate.Usr" />

_________________
Martin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.