-->
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.  [ 2 posts ] 
Author Message
 Post subject: need help!!! can't delete child using bi-directional mapping
PostPosted: Wed Jan 31, 2007 3:04 pm 
Newbie

Joined: Wed Jan 31, 2007 2:55 pm
Posts: 2
okay, this is an age old question, but i can't find a complete solution anywhere on the planet earth. I have tried just about every suggested solution, but nothing is working.

here is my setup.

1. i have a struts - hibernate 2.1 solution.
2. parents to child mapping are bi-directional, inverse=true, cascade="all-delete-orphan"
3. i retrieve the parent object from hibernate, i show it on struts forms, allowing clients to delete child from the set (just do a simple set removal, no hibernate actions involved)
4. i then do a save, hibernate saves all the updates but do not remove the child row from the database. so when i pull up the record again, the same child shows back into the collection set.

before suggesting solutions, here is what i can't do
1. i can't delete child manually because deletion from struts form is not final until client presses save button to finalize the update.
2. i can't use unidirectional mapping because it simply dereference the child from the parent after hibernate update, leaving that orphan row in db.
3. i can't complete the whole thing in one hibernate session, because i have retrieve the parent object, manipulate it a little, display it to the struts form, wait for client action, then manipulate the action, and then do a saveorupdate

hibernate sample mapping for parent
/**
* @hibernate.set cascade="all-delete-orphan" inverse="true" order-by="passenger_id"
* @hibernate.collection-key column="incident_ID"
* @hibernate.collection-one-to-many class="com.bagnet.nettracer.tracing.db.Passenger"
* @return Returns the passengers.
*/
public Set getPassengers() {
return passengers;
}

for child:
/**
* @return Returns the incident.
*
* @hibernate.many-to-one class="com.bagnet.nettracer.tracing.db.Incident"
* column="incident_ID" not-null="true"
*/


please help. i have look everywhere, a lot of people ask this question, but not a direct answer is given.

thanks!


Top
 Profile  
 
 Post subject: a workaround solution
PostPosted: Wed Jan 31, 2007 3:12 pm 
Newbie

Joined: Wed Jan 31, 2007 2:55 pm
Posts: 2
i do have a workaround solution that is ugly but require minimum amount of code change, however, i also have a question on that. If you can answer either the delete orphan question or this one, i will be greatly appreciated

what i could do is during the final transaction, i first retrieve the parent object, then delete it, then do a insert on the new parent object that has child removed from the collection set.

however, the issue i run into with that is child has auto increment key set already, with unsaved-value="0" mapping for the child, child only do an update and hibernate will throw me an exception. is there a hibernate mapping to force child to always insert instead of update?


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