-->
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: composite-id with a foreign key
PostPosted: Thu Mar 16, 2006 7:02 pm 
Newbie

Joined: Thu Jul 15, 2004 1:07 pm
Posts: 9
Hibernate version: 2.1.4

I have three database tables (and hence three hibernate mapped pojos).

Table A, B, and C.

Table B has a composite id consisting of the primary key from A (a_id) and a second column of its own (b_id). This is a unique foreign key of (a_id, b_id).

Table B also has a <list> mapping to C on b_id which exists in C.

From B:

<composite-id unsaved-value="none">
<key-property name="b_id" type="long" column="b_id"/>
<key-many-to-one name="a" class="A" column="a_id"/>
</composite-id>
<list name="c">
<key column="b_id"/>
<index column="c_id"/>
<one-to-many class="C"/>
</list>

Table C is contains the following relationships back to A and B:

<many-to-one name="b" class="B" column="b_id" not-null="true"/>
<many-to-one name="a" class="A" column="a_id" not-null="true"/>

I get the following exception:

net.sf.hibernate.MappingException: Foreign key (COMMON.C [b_id])) must have same number of columns as the referenced primary key (COMMON.B [b_id,a_id])

So my question is, can this type of mapping be done? And if it can, how so? (If not in 2.1.x, can it be done in hibernate 3.x?)

Thanks,
Jay


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.