Hello dear community.
I have a problem with a deleting behavior.
I have a class Order and OrderDetails
in Order class mapping:
Code:
<set name="ordersDetails" inverse="true" fetch="join" cascade="all-delete-orphan" >
<key column="id_order" not-null="true" />
<one-to-many class="OrderDetail" />
</set>
in OrderDetail class mapping
Code:
<many-to-one name="order" class="Order" lazy="false" outer-join="true" cascade="none">
<column name="id_order" not-null="true" />
</many-to-one>
I have one Order and 4 OrderDetails associated with it.
when i call
Code:
session.selete(order)
The questions are:
1. Hibernate deletes only one OrderDetail and tries to delete order, but exception throws due to foreign key constraint. But if i remove
fetch="join" from Order class mapping hibernate deletes all orderdetails and order - that a right behavior. What influence has
fetch="join" on cascade deletion? and why a cannot use this two mapping options together?
2. when i remove
fetch="join" everything is OK, but why hibernate deletes each order detail in separate sql statement like this?
Code:
delete
from
sap.ordersdetails
where
id_detail=?
and version=?
the better way is to delete with one delete statement:
Code:
delete
from
sap.ordersdetails
where
id_order=?
and version=?
Can i tune hibernate like this