-->
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: Many-to-one MappingException
PostPosted: Thu May 18, 2006 11:36 am 
Newbie

Joined: Wed May 17, 2006 10:02 am
Posts: 4
hi all.

i've 2 hbm.xml definitions of 2 table:

the first ( with a composite-id PK ):

......
<composite-id name="Id" class="MyClass">
<key-property
name="Name1"
column="Column1"
type="string"
/>
<key-many-to-one
name="Name2"
class="MyClass2"
column="Column2"
/>
</composite-id>
......
......
......

<many-to-one
name="Name3"
column="Column3"
class="MyClass2"
not-null="true"
>

As you see the 2nd key is a Foreign Key on another class and his hbm.xml look like this:


<composite-id name="Id" class="MyClass2">
<key-property
name="Name1"
column="Column1"
type="integer"
/>
<key-many-to-one
name="Name2"
class="MyClass3"
column="Column3"
/>
</composite-id>


When i start session i receive this Exception:

"Foreign key must have same number of columns as the referenced primary key"

Why i have this Exception? I've generated all the hbm.xml and classes with Hibernate Synchronizer on Eclipse 3.1.2. Is a plugin bug or a Hibernate bug ?? Or what ?

Thanx all

Byez


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 12:10 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
If you get the exception "Foreign key must have same number of columns as the referenced primary key", it means the number of columns defined either in <many-to-one> or <key-many-to-one> are not matching the columns defined in <set> element with bi-directional relation.

Also you have <key-many-to-one> and <many-to-one> define relation to the same class MyClass2 but with columns Column2 and Column3 respectively. Do you want to have two relations to the same class on different columns?


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.