ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Hibernate Your Data
Subject:   Composite keys in one-to-many or many-to-many
Date:   2004-08-09 06:57:16
From:   jeffcaz
Great tutorial. My questions is, can you and if so how do you set up a relationship that uses a composite primary key. I know it is not the best way to design, but that is not the question.
Can you do something like this?


<set name="orderItems" table="order_items"
cascade="all" inverse="true">
<!-- <key column="order_id"/> -->
<composite-id>
<key-property name="orderId"/>
<key-property name="productId"/>
</composite-id>
<one-to-many class="test.hibernate.OrderItem"/>
</set>


1 to 1 of 1
1 to 1 of 1