These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many-to-many cascade delete does not work
PostPosted: Sun Dec 07, 2008 2:12 pm 
Newbie

Joined: Sun Dec 07, 2008 1:29 pm
Posts: 6
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.