users
[Top] [All Lists]

RE: [cinjug-users] Hibernate3 deletes due to removal of list items

To: <twcrone@xxxxxxxxxxxxx>, <users@xxxxxxxxxx>
Subject: RE: [cinjug-users] Hibernate3 deletes due to removal of list items
From: "Forsythe, Brian" <Brian.Forsythe@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 6 Sep 2006 13:34:05 -0400
Delivered-to: mailing list users@cinjug.org
Mailing-list: contact users-help@cinjug.org; run by ezmlm
References: <fcae83a15548.44fea036@insightbb.com>
Thread-index: AcbRv1Lo+Y0N+XjnT9ybxcVzE0/eAQAG1O6u
Thread-topic: [cinjug-users] Hibernate3 deletes due to removal of list items
You want to look into the cascade attribute in the docs.  There are several 
options for cascade, including lock, update, and delete.

________________________________

From: twcrone@xxxxxxxxxxxxx [mailto:twcrone@xxxxxxxxxxxxx]
Sent: Wed 9/6/2006 10:17 AM
To: users@xxxxxxxxxx
Subject: [cinjug-users] Hibernate3 deletes due to removal of list items


I currently have an application that has a hierchical domain model that has 
objects that have lists of other objects that have lists of other objects that 
have lists...It goes about 4-5 layers deep and I need to be able to saveUpdate 
the main object and have changes to the lists at n level to take effect.  
Currently removals of items in the list at the first level causes deletes but 
at lower levels items removed don't cause deletes when I persist the main 
object.
 
I am using a "bag" element to define these relationships in the mapping files 
as such...
 
<hibernate-mapping>
 <class name="MainObjectClass" table="Main" lazy="false">
  <!-- ID field -->
  <id name="uniqueId" type="int" column="mainid">
   <generator class="increment"/>
  </id>
  
  ...
    
  <bag name="firstLevelObjects" cascade="all" lazy="false">
   <key column="mainid" not-null="true"/>
   <one-to-many class="FirstObjectClass"/>
  </bag>
  
  ...  
  
 </class>
 <class name="FirstLevelObjectClass" table="First" lazy="false">
  <!-- ID field -->
  <id name="uniqueId" type="int" column="firstid">
   <generator class="increment"/>
  </id>
  
  ...
  
  <bag name="secondLevelObjects" cascade="all" lazy="false">
   <key column="firstid" not-null="true"/>
   <one-to-many class="SecondLevelObjectClass"/>
  </bag>
  ...
  
 </class>
</hibernate-mapping>

So when I saveUpdate MainObject, any removals from FirstLevelObjects list 
causes deletes (good).  However any removals from SecondLevelObjects list does 
not cause deletes (bad).  I guess somehow I am interfering with Hibernate's 
tracking of changes somehow.  Anyone know why this might be happening?  I can 
put in deletes explicity but I'd rather just let Hibernate do it for me.
 
Thanks,
 
- Todd

 

 


<Prev in Thread] Current Thread [Next in Thread>