Hello
I am having a problems mapping a many-to-many association where the middle table also has fields other than the primary keys of the other two tables.
The tables are:
Purchase (PK -> purchase_id)
Item (PK -> item_id)
ItemPurchase (PKs -> item_id, purchase_id)
The ItemPurchase table also has the column "quantity".
I also have the corresponding beans for these tables.
On the Hibernate In Action Book I read that you can make a mapping for the ItemPurchase table and define two many-to-one associations. What I don't get is how would I map the primary keys of the table. Here is my current hibernate mapping for this class.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="controldeutiles.model.businessobject">
<class name="ItemPurchase">
<id></id>
<many-to-one name="purchase" column="purchase_id" class="Purchase" not-null="true" />
<many-to-one name="item" column="item_id" class="Item" not-null="true" />
<property name="quantity" type="integer"></property>
<property name="unit_amount" type="double" />
<property name="total_amount" type="double" />
</class>
</hibernate-mapping>
What should go between the "id" tags?