File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Composite Foreign Key that maps to Unique Constraint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Composite Foreign Key that maps to Unique Constraint" Watch "Composite Foreign Key that maps to Unique Constraint" New topic
Author

Composite Foreign Key that maps to Unique Constraint

Gir Dus
Greenhorn

Joined: Sep 13, 2010
Posts: 1
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!


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Composite Foreign Key that maps to Unique Constraint