-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cascading delete not working
PostPosted: Thu Jun 17, 2004 12:11 pm 
Newbie

Joined: Thu May 06, 2004 8:14 pm
Posts: 18
I have a Provider object which has child Facility objects:

/**
* @hibernate.set role="facilities" lazy="true" cascade="delete"
* @hibernate.collection-key column="provider_id"
* @hibernate.collection-one-to-many class="com.webify.hta.domain.Facility"
*/
public Set getFacilities() {
return facilities;
}

Notice the cascade delete setting. I'm getting an error when I try to delete a Provider object:

"Cannot add or update a child row: a foreign key constraint fails"

Now the SQL right before that is this statement:

Hibernate: update hta_facility set provider_id=null where provider_id=?

Now why is Hibernate trying to do this? Shouldn't it be deleting the Facility objects and then deleting the top-level Provider object (i.e. delete the leaf nodes of the object tree first). Why is Hibernate performing updates in the first place? provider_id is marked as not null so this statement will fail.

I'm using mysql 4.0.18.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 3:44 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://www.hibernate.org/hib_docs/refer ... d-cascades

all-delete-orphan

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 4:32 pm 
Newbie

Joined: Tue Oct 05, 2004 11:28 am
Posts: 10
This one keeps burning me. I have found that (on case a case by case basis) I can solve this one in the following ways:

Sometimes inverse="true" on the parent collection solves it, but this doesn't help if I am managing the children via the parent collection.

Sometimes cascade="all-delete-orphan" on the parent collection solves it, when i [b]am[/b/ managing the children via the parent collections.

Sometimes I simply need a many-to-one reference in the child mapping (and object) that points back to the parent.

With these three bits of info I have been able to overcome all of my mapping mistakes.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 5:03 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
this is much easier and well documented

it only depends one how you have configured transitive persistence (attribute cascade).

If your association is bidirectionnal, this is another thing: you must manage your instances--> read hibernate in action, forum, wiki, reference guide about addChild, removeChild methods ...

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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