-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problems with automatic Child-Collection deletion
PostPosted: Mon Mar 15, 2004 6:53 am 
Newbie

Joined: Mon Feb 16, 2004 7:11 am
Posts: 13
Hello everybody!

I use the following combination of Objects in Hibernate:
Order having a Collection (<set>) of OrderParameter objects mapped to it.

Now what I would like to do is to be able to delete an Order-object. Consequently removing all OrderParameters that it has among it. To do that I added a "cascade=delete" to the respective collection mapping.

Now what Hibernate does now is an "UPDATE OrderParameters SET order_id=NULL where order_id=?" resulting in that my database says that an OrderParameter may not exists without a parent.

Can somebody help me?! Did I get the Collection concept wrong? Or to I have to map the Collection in another way?

Thx, Tim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 9:30 am 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Deleting something from a collection generally only deletes the RELATIONSHIP between the parent and the child, not the child itself. If you want the behaviour where deleting from a collection also deletes the child try cascade="all-delete-orphan" or alternatively manually delete the child.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 9:41 am 
Newbie

Joined: Mon Feb 16, 2004 7:11 am
Posts: 13
Ok, the following did help, and I don't really know why:
I added the "delete-orphans", after that Hibernate was still trying to set the Childs to NULL, ergo resulting in a Contraint-Violation.

Then I set the "inverse"-attribute to true and viola, it is doing what I expected it to do. So why is that?!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 9:44 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You didn't read the "Parent Child Relationship" chapter of the documentation. It was recommended before you clicked on the link to this forum. This is also helpful if you want to understand "inverse":

http://www.hibernate.org/155.html

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 15, 2004 10:07 am 
Newbie

Joined: Mon Feb 16, 2004 7:11 am
Posts: 13
Well, I did, but seems I didn't do it closely enough!
Anyway, thx for the help!


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