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.  [ 9 posts ] 
Author Message
 Post subject: delete with cascade issue..
PostPosted: Mon Sep 15, 2003 2:43 pm 
Newbie

Joined: Sun Aug 31, 2003 1:20 am
Posts: 17
Hi all,

I get this error:

Flush during cascade is dangerous - this might occur if an object was deleted and then re-saved by cascade

when I try to delete a child. The child and the parent are associated using a bi-directional association as follows:

<set name="child"
table="childTable"
cascade="save-update"
inverse="true"
>
<key column="parent_id" />
<one-to-many class="ChildClass" />
</set>


the child has a many to one reference to the parent as specified in the documentation.

In my unit test, I create the parent, create the child and associate the child with the parent. All this works fine. Then when I am done and ready to clean up the objects used in my test, the deletes fail and give me the error above. It seems from the parent child section in the documenation that I should be able to delete children fine this way.

Anything I should be looking for?

Thanks


Top
 Profile  
 
 Post subject: Oooopss...
PostPosted: Mon Sep 15, 2003 3:42 pm 
Newbie

Joined: Sun Aug 31, 2003 1:20 am
Posts: 17
I am using HIbernate 2.0.3. Basically following the exact configuration used in the parent child section in the documentation.


Top
 Profile  
 
 Post subject: Flush during cascade
PostPosted: Mon Sep 15, 2003 3:48 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:44 pm
Posts: 20
This faq: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.


Top
 Profile  
 
 Post subject: Ooohh...
PostPosted: Mon Sep 15, 2003 4:06 pm 
Newbie

Joined: Sun Aug 31, 2003 1:20 am
Posts: 17
ashoknan, thanks for the reply. I tried that and it worked.

So when I am deleting the child, I should remove it from the association collection in the parent, save the parent, then delete the child.

parent.getChildren().remove(child);
session.save(parent);
session.delete(child);


///commit transaction....

The issue for me is that one session retrieves/creates the children and another session does the delete.

Thanks again..


Top
 Profile  
 
 Post subject: Cascade Delete
PostPosted: Mon Sep 15, 2003 5:27 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 6:44 pm
Posts: 20
>>The issue for me is that one session retrieves/creates the children and >>another session does the delete.

What is the issue here..it similar to what we do in normal transaction processes.


Top
 Profile  
 
 Post subject: Re: Ooohh...
PostPosted: Fri Sep 26, 2003 5:39 am 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
haytham wrote:
ashoknan, thanks for the reply. I tried that and it worked.

So when I am deleting the child, I should remove it from the association collection in the parent, save the parent, then delete the child.

parent.getChildren().remove(child);
session.save(parent);
session.delete(child);


///commit transaction....

The issue for me is that one session retrieves/creates the children and another session does the delete.

Thanks again..


this example is a one-to-many association, how about many-to-many?????


Top
 Profile  
 
 Post subject: Re: Ooohh...
PostPosted: Thu Oct 16, 2003 4:23 pm 
Regular
Regular

Joined: Tue Oct 14, 2003 11:11 pm
Posts: 62
Location: Brasil/Curitiba
haytham wrote:
parent.getChildren().remove(child);
session.save(parent);
session.delete(child);

///commit transaction....
Thanks again..


Do I need remove the child of the Collection?
parent.getChildren().remove(child);

To do this, do I have to implement both equals and hashcode methods?

// Can I do only like this?
Code:
session.save(parent);
session.delete(child);
///commit transaction....
Thanks again..


thanks a lot...

_________________
Ricardo Lecheta


Top
 Profile  
 
 Post subject: Re: Ooohh...
PostPosted: Wed Dec 24, 2003 2:16 am 
Beginner
Beginner

Joined: Wed Oct 29, 2003 5:27 am
Posts: 30
Ricardo wrote:
Do I need remove the child of the Collection?
parent.getChildren().remove(child);

To do this, do I have to implement both equals and hashcode methods?

// Can I do only like this?
Code:
session.save(parent);
session.delete(child);
///commit transaction....
Thanks again..


Yes, you'd better implement both equals() and hashcode(). I have checked on my .java files generated by hbm2java and found out that classes having one-to-many relationships with other classes (that is: these classes play the Parent roles in one-to-many relationships) all have implement both equals() and hashcode().


Top
 Profile  
 
 Post subject: I get the same error
PostPosted: Sun Oct 26, 2008 8:43 am 
Newbie

Joined: Sun Oct 26, 2008 8:38 am
Posts: 1
I get the same error


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