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!
|