-->
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: [HELP] Coposite Key Maping One-to-Many
PostPosted: Tue May 11, 2004 2:20 pm 
Newbie

Joined: Wed Oct 08, 2003 8:52 am
Posts: 10
Hi All,
I am lost trying to create a relationship for table with composite key. Here is my example:

<hibernate-mapping>
<class name="eg.User" table="user">
<composite-id name="compId" class="edu.umn.web.idea.data.entity.UserPK">
<key-property column="user_id" length="16" name="userId" type="string"/>
<key-property column="year" length="4" name="year" type="string"/>
</composite-id>
<property column="first_name" length="64" name="firstName" not-null="true" type="string"/>
.
.
.

<set name="roles">
<key>
<column name="id"/>
<column name="year"/>
</key>
<one-to-many class="eg.UserRole"/>
</set>

</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="eg.Role" table="role">
<composite-id>
<key-many-to-one column="id" class="edu.umn.web.idea.data.entity.User" name="id"/>
<key-property column="year" length="4" name="year" type="string"/>
<key-property column="role" length="4" name="role" type="integer"/>
</composite-id>
<property column="active" length="1" name="active" not-null="true" type="byte"/>
.
.
.
</class>
</hibernate-mapping>


At boot time, this is the message I got:
.
.
FATAL 2004-05-11 12:53:11,445 [main] (eg.ApplicationInit) - Error obtaining a Hibernate SessionFactory!
net.sf.hibernate.MappingException: Foreign key (role [id])) must have same number of columns as the referenced primary key (user [user_id,year])
at net.sf.hibernate.mapping.ForeignKey.setReferencedTable(ForeignKey.java:60)
.
.



What am I doing wrong in my role mapping??


Thanks

JavaLamer


Top
 Profile  
 
 Post subject: Ooops
PostPosted: Tue May 11, 2004 2:22 pm 
Newbie

Joined: Wed Oct 08, 2003 8:52 am
Posts: 10
I tried to make the above generic but forgot a few things.

Sorry
JavaLamer


Top
 Profile  
 
 Post subject: I Got It
PostPosted: Tue May 11, 2004 4:06 pm 
Newbie

Joined: Wed Oct 08, 2003 8:52 am
Posts: 10
Ok, with some reading, I think I got it.

OLD
Quote:
<hibernate-mapping>
<class name="eg.Role" table="role">
<composite-id>
<key-many-to-one column="id" class="eg.User" name="id"/>
<key-property column="year" length="4" name="year" type="string"/>
<key-property column="role" length="4" name="role" type="integer"/>
</composite-id>
<property column="active" length="1" name="active" not-null="true" type="byte"/>
.
.
.
</class>
</hibernate-mapping>



NEW
Quote:
<hibernate-mapping>
<class name="eg.Role" table="role">
<composite-id>
<key-many-to-one class="eg.User" name="id">
<column name="id"/>
<column name="year"/>
</key-many-to-one>
<key-property column="role" length="4" name="role" type="integer"/>
</composite-id>
<property column="active" length="1" name="active" not-null="true" type="byte"/>
.
.
.
</class>
</hibernate-mapping>


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.