I have to map a less than normalised table structure with complex primary keys and whatnot and have run into a problem while doing this.
Say that I have these three tables:
* Table1:
Primary key: table1ID
* Table2:
Primary key (composite): table2ID, table1ID
- table1ID is a foreign key to Table1.
* Table3:
Primary key: table3ID
foreign key (composite): table2ID, table1ID
How do I express the many-to-one relationship in Table3?
The Table2 primary key mapping:
<composite-id name="table2Key" class="db.Table2Key">
<key-property name="table2ID" type="long" column="table2ID"/>
<key-many-to-one name="table1" class="db.Table1" column="table1ID"/>
</composite-id>
I've tried this for the foreign key mapping in Table3:
<many-to-one name="table2" class="db.Table2">
<column name="table2ID"/>
<column name="table1ID"/>
</many-to-one>
Which naturally won't work since the second column (table1ID) is a class reference and not a field. I can't find anything in the Hibernate manual for mapping this kind of composite foreign key.
/Bj
|