Hibernate version: 3.2.1.ga
Full stack trace of any exception that occurs:
Name and version of the database you are using: hsqldb 1.8.0.7
Hello,
I can't manage to have a cascade delete working for the following model.
The model looks like:
|Customer|----*|Order|----<**>-----|Product|
i.e. Customer one-to-many Order, Order many-to-many Product
The problem is that using the mapping below if I delete a Product that is already referenced by the PRODUCT_ORDER_REL_, whenever loading a Customer that has an Order that contains that Product the Product will be loaded meaning that the Product was not deleted.
PS:
<?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="perfectjpattern.jee.database.datamodel">
<!-- Customer is a strong entity that contains Orders -->
<class name="Customer" table="CUSTOMER_" >
<id name="id">
<generator class="native" />
</id>
<property name="name" column="NAME" update="false" />
<bag name="orders" inverse="true" cascade="all, delete-orphan">
<key column="CUSTOMER_ID" on-delete="cascade" />
<one-to-many class="Order" />
</bag>
</class>
<!-- Order is a weak entity that depends on Customer and contains Products -->
<class name="Order" table="ORDER_" >
<id name="id">
<generator class="native" />
</id>
<many-to-one name="customer" class="Customer"
column="CUSTOMER_ID" cascade="save-update" />
<list name="products" table="PRODUCT_ORDER_REL_"
inverse="true" cascade="all, delete-orphan" >
<key column="ORDER_ID" />
<list-index column="ID" />
<many-to-many class="Product" column="PRODUCT_ID" />
</list>
<property name="date" column="DATE" update="false" />
</class>
<!-- Product is a strong entity and references the orders -->
<class name="Product" table="PRODUCT_" >
<id name="id">
<generator class="native" />
</id>
<property name="name" column="NAME" update="false" />
<property name="listPrice" column="LIST_PRICE" update="true" />
<list name="orders" table="PRODUCT_ORDER_REL_"
inverse="true" cascade="all, delete-orphan">
<key column="PRODUCT_ID" />
<list-index column="ID" />
<many-to-many class="Order" column="ORDER_ID" />
</list>
</class>
</hibernate-mapping>
|