• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

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:

distributionlistid (Primary Key)

serviceuserid (Primary Key)

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:

<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>
<set name="listmembers" inverse="true">
<column name="DISTRIBUTIONLISTID" precision="22" scale="0" not-null="true" />
<one-to-many class="gov.va.med.logService.hibernate.Listmember" />

<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 name="serviceuser" class="gov.va.med.logService.hibernate.Serviceuser">
<column name="SERVICEUSERID" precision="22" scale="0" />

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
    Bookmark Topic Watch Topic
  • New Topic