Hibernate version:2.1.7c
[
Name and version of the database you are using:Oracle 8
I have the following senario and need comments about the mappings:
Quote:
ITEM (ITEM_ID, NAME)
ORDER (ORDER_ID, DESCRIPTION)
ORDER_ITEM (ITEM_ID, ORDER_ID, QTY,PRICE)
My Order.hbm.xml is as follows:
Code:
<hibernate-mapping>
<class name="dao.Order" table="ORDER">
<id name="id" type="string">
<column name="ORDER_ID" length="10"/>
<generator class="assigned"/>
</id>
<set name="items" table="ITEM_ORDER">
<key column="ORDER_ID"/>
<composite-element class="dao.ItemOrder">
<many-to-one name="item" class="dao.Item">
<column name="ITEM_ID"/>
</many-to-one>
<property name="qty" column="QTY" type="integer"/>
<property name="price" column="PRICE" type="double"/>
</composite-element>
</set>
<property name="desc" column="DESCRIPTION" type="string"/>
</class>
</hibernate-mapping>
My Item.hbm.xml is as follows:
Code:
<hibernate-mapping>
<class name="dao.Item" table="ITEM" >
<id name="id" type="string">
<column name="ITEM_ID" length="10"/>
<generator class="assigned"/>
</id>
<property name="desc" column="NAME" type="string"/>
</class>
</hibernate-mapping>
The ITEM_ORDER dao has the setters/getters for :
Item item;
private double price;
private int qty;
- and it doesn't have a seperate hbm.xml since the mapping is embedded inside order.hbm.xml via a
<composite-element> tag.
How to enable the composite primary key for the ITEM_ORDER ? withing the <composite-element> the items set has ORDER_ID defined as the key. But how to specify the ITEM_ID as a part of the composite p.key of the ITEM_ORDER ? Can i define it inside the <composite-element> tag?
please help!