Hi All,
I have a newbie question.
I have an Order class, which contains a set of OrderItems. I am persisting the OrderItems as a set of composite-elements, stored in a table called ORDER_ITEM. Each OrderItem has a relationship to an Item object. Can I nest within each orderItem a unique many-to-one relationship with an Item entity? In order words, I want to persist the Order and related OrderItems without saving any Items.
The mappings are as follows:
Order.hbm.xml:
<class name="poc.domain.Order" schema="HIBERNATE" table="ORDER">
<id name="id" type="long" column="ID">
<generator class="native"/>
</id>
<property name="orderDate" type="date" column="ORDER_DATE" />
<property name="total" type="double" column="TOTAL" />
<set name="orderItems" schema="HIBERNATE" table="ORDER_ITEM">
<key column="ORDER_ID" />
<composite-element class="poc.domain.OrderItem">
<property name="count" type="integer" column="ITEM_COUNT" />
<many-to-one name="item" class="poc.domain.Item" column="ITEM_ID"
unique="true" update="false" insert="false" />
</composite-element>
</set>
</class>
Item.hbm.xml:
<class name="poc.domain.Item" schema="HIBERNATE" table="ITEM">
<id name="id" type="long" column="ID">
<generator class="native"/>
</id>
<property name="name" type="string" column="NAME" />
<property name="description" type="string" column="DESCRIPTION" />
<property name="price" type="double" column="PRICE" />
</class>
I am getting the following error, which I guess means I can't do the nesting but I wanted to make sure:
[object references an unsaved transient instance - save the transient instance before flushing: poc.domain.Item]: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: poc.domain.Item
Thanks!
Steve
|