Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Hibernate: Foreign key must have same number of columns as the referenced primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Hibernate: Foreign key must have same number of columns as the referenced primary key" Watch "Hibernate: Foreign key must have same number of columns as the referenced primary key" New topic
Author

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

Ben Hagadorn
Greenhorn

Joined: Mar 28, 2006
Posts: 25
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate: Foreign key must have same number of columns as the referenced primary key