Hi,
I've got a probably real stupid problem here, but I just can't help it for now, so I'll ask for help:
I have 2 classes: Order and OrderLine, the last composing the first.
When I try to save an order, when the SQL INSERTs get executed for the OrderLines, they don't include the id_order field.
Is that because there is no navigability from OrderLine to Order?
I guess there is surely a way to work around that... But I just didn't found it yet...
Hopes someone takes the time to lead a Hibernate Newbie by the hand.
Thanks
Alex
Hibernate version:
2.1.7c
Mapping documents:
for
Order
Code:
<class name="Order" table="orders">
<cache usage="read-write"/>
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">orders_id_seq</param>
</generator>
</id>
<many-to-one name="customer" column="id_user" class="User" not-null="true" />
<many-to-one name="deliveryAddress" class="Address" column="id_address_delivery"
unique="true" cascade="save-update" not-null="true" />
<property name="creationDate" column="ts" type="date" not-null="true" insert="false" />
<property name="shippingCost" column="shipping" type="integer"/>
<property name="payment" column="payment" type="string" length="16"/>
<property name="status" column="status" type="char"/>
<set name="lines" table="order_lines" lazy="false" cascade="all" batch-size="10" >
<cache usage="read-write"/>
<key column="id_order"/>
<one-to-many class="OrderLine"/>
</set>
</class>
and for
OrderLineCode:
<class name="OrderLine" table="order_lines">
<cache usage="read-write"/>
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">order_lines_id_seq</param>
</generator>
</id>
<many-to-one name="referenceProduct" column="id_product" class="be.barracuda.model.products.Product" not-null="true" />
<many-to-one name="referenceOption" column="id_option" class="be.barracuda.model.products.Option" not-null="true" />
<property name="quantity" column="quantity" type="int" not-null="false"/>
<property name="price" column="price" type="int" not-null="false"/>
</class>
The generated SQL (show_sql=true):Code:
Hibernate: insert into order_lines (id_product, id_option, quantity, price, id) values (?, ?, ?, ?, ?)