• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ben Hagadorn
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic