• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic