-->
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.  [ 3 posts ] 
Author Message
 Post subject: Error while deleting an 1-n child class
PostPosted: Thu Oct 23, 2003 8:43 pm 
Beginner
Beginner

Joined: Sat Oct 18, 2003 8:00 pm
Posts: 22
I have two classes Post (1) and Comment (n). The Comment has the following configuration :

Post.hbm.xml snippet:
...
<set name="comments" order-by="created desc" cascade="all">
<key column="post_id"/>
<one-to-many class="net.eyde.personalblog.beans.Comment"/>
</set>
...

Comment.hbm.xml snippet:
...
<many-to-one name="post" class="net.eyde.personalblog.beans.Post" column="post_id"/>
...

Delet Code Code:
....
session = sf.openSession();
session.delete(session.load(Comment.class, commentId));
session.flush();
session.close();
....

When I delete a post everythings work fine, the related comments are deleted, but when I delete a comment with the following code, I get the error :

net.sf.hibernate.HibernateException: Flush during cascade is dangerous -
this might occur if an object was deleted and then re-saved by cascade


1


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2003 1:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
http://www.hibernate.org/117.html#A20


Top
 Profile  
 
 Post subject: cascade all
PostPosted: Fri Oct 24, 2003 9:10 am 
Beginner
Beginner

Joined: Sat Oct 18, 2003 8:00 pm
Posts: 22
gavin wrote:
http://www.hibernate.org/117.html#A20


page content: "Hibernate throws: Flush during cascade is dangerous.
This almost always happens because you forgot to remove a deleted instance from an association with cascading save enabled. You should remove deleted objects from associations before flushing the session.
"

Does it means that I must choose :

* Cascade delete - Having more work to create the childs adding it to the collections and saving it separated.
* Cascade all - Having more work on deletion, having to get the associated 1 side of the relation from child, and removing from there, and deleting the child after all.

After all, I didn't get the message, since I'm deleting the side of cascade that should not thrown any cascade. The cascade is from the 1 side to the N side.

Isn't there any approache that allows me to cascade from parent to child (1 to n side), and even let me delete child without having to touch the parent collection (that contains the N side).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.