-->
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.  [ 2 posts ] 
Author Message
 Post subject: trouble with cascade delete
PostPosted: Thu Jan 03, 2008 12:26 am 
Newbie

Joined: Wed Oct 10, 2007 9:30 pm
Posts: 6
Hi,

I'm pretty new to hibernate and i'm not really sure how the cascade works. I did some test on deleting a "Parent" with a collection of "ChildBag" however deletion is not happening in the "ParentBag" and the other records are deleted fine. The weird thing is I didn't get trouble when saving the "Parent" object since all data is saved into all tables.

I did a test to check whether simply deleting the "ChildBag" can propagate the change to the "ParentBag" and it seems like it is working, so I guess I did the wrong mapping in the <bag>

A simple mapping and some information about what i used is below. Any help is appreciated


Hibernate version: 3.2.3.ga

Mapping documents:
Code:
   <class name="Parent" table="parent" lazy="false">
      <id name="id" column="object_id">
         <generator class="native"/>
      </id>
      <bag name="bags" inverse="true" order-by="bag_id" lazy="false" cascade="all">
         <key column="object_id" not-null="true" on-delete="cascade" />
         <one-to-many class="ChildBag"/>
      </bag>
   </class>

   <joined-subclass name="Child" table="child_table" extends="Parent">
      <key column="object_id"/>
      <property name="data" column="from_info"/>
   </joined-subclass>

   <class name="ParentBag" table="parent_bag" lazy="false">
      <id name="bagid" column="bag_id">
         <generator class="native" />
      </id>
      <property name="dateAdded" column="date_added" type="timestamp" />
   </class>

   <joined-subclass name="ChildBag" table="child_bag" lazy="false" extends="ParentBag">
      <key column="bag_id" not-null="true" on-delete="cascade"/>
      <property name="priority" />
      <property name="object_id" />
   </joined-subclass>

Code between sessionFactory.openSession() and session.close():
session.delete(parentObject);
session.getTransaction().commit();


Name and version of the database you are using: MSSQL 2005


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 03, 2008 2:18 am 
Newbie

Joined: Wed Oct 10, 2007 9:30 pm
Posts: 6
finally I got it working by specifying

cascade="all-delete-orphan"

and removing

on-delete="cascade"

Code:
<class name="Parent" table="parent" lazy="false">
      <id name="id" column="object_id">
         <generator class="native"/>
      </id>
      <bag name="bags" inverse="true" order-by="bag_id" lazy="false" cascade="all-delete-orphan">
         <key column="object_id" not-null="true" />
         <one-to-many class="ChildBag"/>
      </bag>
   </class>


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

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.