-->
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.  [ 4 posts ] 
Author Message
 Post subject: Foreign key must have same number of columns as the referenc
PostPosted: Wed Apr 19, 2006 4:27 pm 
Newbie

Joined: Wed Apr 19, 2006 4:25 pm
Posts: 7
I have the following 3 tables in my DB:

Distributionlist
distributionlistid (Primary Key)

Serviceuser
serviceuserid (Primary Key)

Listmember
distributionlistid (Foreign key to Distributionlist)
serviceuserid (Foreign key to Serviceuser)

Primary key is a composite of distributionlistid and serviceuserid



(basically Listmember is an assoc table that allows me to map Listmembers and Distributionlists together)




I also have these hibernate mappings:




<hibernate-mapping>
<class name="gov.va.med.logService.hibernate.Distributionlist" table="DISTRIBUTIONLIST">
<id name="distributionlistid" type="java.lang.Long">
<column name="DISTRIBUTIONLISTID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">SDISTRIBUTIONLIST</param>
</generator>
</id>
<set name="listmembers" inverse="true">
<key>
<column name="DISTRIBUTIONLISTID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="gov.va.med.logService.hibernate.Listmember" />
</set>
</class>
</hibernate-mapping>



<hibernate-mapping>
<class name="gov.va.med.logService.hibernate.Listmember" table="LISTMEMBER">
<composite-id name="id" class="gov.va.med.logService.hibernate.ListmemberId">
<key-many-to-one name="distributionlist" class="gov.va.med.logService.hibernate.Distributionlist">
<column name="DISTRIBUTIONLISTID" precision="22" scale="0" />
</key-many-to-one>
<key-many-to-one name="serviceuser" class="gov.va.med.logService.hibernate.Serviceuser">
<column name="SERVICEUSERID" precision="22" scale="0" />
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>





When I try to run I get this error:

Foreign key (FK5E33B8B89E456429:LISTMEMBER [DISTRIBUTIONLISTID])) must have same number of columns as the referenced primary key (LISTMEMBER [SERVICEUSERID,DISTRIBUTIONLISTID])



Could someone please tell me how to change my mapping to correct this error? Any help at all would be appreciated. Thanks.

- Ben


Top
 Profile  
 
 Post subject: ARG
PostPosted: Fri Jun 23, 2006 9:59 am 
Newbie

Joined: Fri Jun 23, 2006 9:25 am
Posts: 10
I have the exact same problem. Any example or help that anyone could provide would be awesome.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 10:42 am 
Newbie

Joined: Wed Apr 19, 2006 4:25 pm
Posts: 7
We found that the error went away when we changed the mapping files like this:

DISTRIBUTIONLIST:

<set name="listmembers" table="LISTMEMBER" lazy="false">
<key column="DISTRIBUTIONLISTID" />
<one-to-many class="gov.va.med.logService.hibernate.Listmember"/>
</set>



SERVICEUSER:

<set name="listmembers" table="LISTMEMBER" lazy="false">
<key column="SERVICEUSERID" />
<one-to-many class="gov.va.med.logService.hibernate.Listmember"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 9:44 am 
Newbie

Joined: Fri Jun 23, 2006 9:25 am
Posts: 10
Thanks you for your suggestion. I don't understand why the composite id specification is necessary though. I haven't been able to acquire any good documentation explaining the composite id.. maybe I should keep digging. Could you provide an example of your Association table class file?


I've seen examples of setting up and using association tables, but they use many-to-many mappings. See : <a href="http://www.java2s.com/Code/Java/Hibernate/ManyToManyMapCascadeLoad.htm"> http://www.java2s.com/Code/Java/Hiberna ... deLoad.htm</a>

I've emplemented such a setup but haven't had any success. (Except that I'm not getting any errors, but I'm not getting the data persisted either.) See <a href="http://forum.hibernate.org/viewtopic.php?t=961274">http://forum.hibernate.org/viewtopic.php?t=961274</a>

As always, any help provided is awesome!


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