-->
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: Cascading delete children doesn't
PostPosted: Fri Aug 19, 2005 6:28 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
I have an Order class, with a contained Set of OrderItems, marked with 'cascade="all-delete-orphan"'. When I remove an item from the OrderItems set and then save the Order, I want the OrderItem to be deleted, and I imagined that it would be, given that cascade. However, what is happening instead is that MySQL returns a constraint error as a result of an attempt to set order_item.order_id to null. Why is it trying to set the parent id property to null instead of deleting the row? What sort of thing should I be looking for here?


(Hibernate 2.1.8).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 9:58 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
I am not sure whether this will help:

Set inverse="true" as follows in your mapping:

<set
name="orderItems"
inverse="true"
cascade="all-delete-orphan"
>
......

Try it out


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:05 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
[quote="jaikiran"]I am not sure whether this will help:

Set inverse="true" as follows in your mapping:

This did indeed solve the problem. Still haven't quite got my head around the inverse business, though. Is it possible to give me a one-sentence explanation of why this solves my problem? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:33 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
Quote:
What about the inverse mapping attribute? For you, and for Java, a bi-directional link is simply a matter of setting the references on both sides correctly. Hibernate however doesn't have enough information to correctly arrange SQL INSERT and UPDATE statements (to avoid constraint violations), and needs some help to handle bi-directional associations properly. Making one side of the association inverse tells Hibernate to basically ignore it, to consider it a mirror of the other side. That's all that is necessary for Hibernate to work out all of the issues when transformation a directional navigation model to a SQL database schema. The rules you have to remember are straightforward: All bi-directional associations need one side as inverse. In a one-to-many association it has to be the many-side, in many-to-many association you can pick either side, there is no difference.


Also, this link might help a bit on the same:

http://neeraj.name/category/java/hibernate/


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 10:35 am 
Regular
Regular

Joined: Wed Jul 27, 2005 2:33 am
Posts: 118
The previous qoute was from:

http://www.hibernate.org/hib_docs/v3/re ... orial.html


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.