• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Composite Foreign Key that maps to Unique Constraint

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have 2 tables (table1 & table2). Table 1 has 2 columns(table1ColA & table1ColB) which are unique. Table2 has 2 similar columns which I define as foreign keys of Table1.

So Table2 (table2ColA & table2ColB) == foreign key reference to Table1(table1ColA & table1ColB)

When I try to generate the Hibernate Mapping Files, this is the error I get

"org.hibernate.MappingException: Foreign key (FKCB773E2441174225:table2 [table2ColA,table2ColB])) must have same number of columns as the referenced primary key (table1 [id])"

Why is hibernate trying to pick table1's primary key as the referenced primary key when in mySQL the foreign key is defined as (table1ColA & table1ColB) which have unique constraint on them? How do I tell Hibernate to use the foreign key defined in mySQL as the foreign key and not assume that the primary key of the referenced table is the foreign key? Table definition can be found below. Thanks!


 
catch it before it slithers away! Oh wait, it's a tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic