-->
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: Does cascade="all_delete_orphan" only work in the
PostPosted: Mon Aug 16, 2004 5:43 pm 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
When I use cascade="all-delete-orphan" will it only work in the hibernate session where I select the data? I would like to "update" in a new session, though I think it will not delete orphans. Thanks, Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 16, 2004 5:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It will delete the orphans if you keep the same collection instance Hibernate give to you.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 10:42 am 
Newbie

Joined: Mon Nov 14, 2005 7:07 am
Posts: 9
emmanuel wrote:
It will delete the orphans if you keep the same collection instance Hibernate give to you.


And if I have to make the update (in my case removal of children) in another collection (lost since I have made entity->DTO->entity)?
Is it possible to get hibernat on the track again?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 12:41 pm 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
matsekberg wrote:
emmanuel wrote:
It will delete the orphans if you keep the same collection instance Hibernate give to you.


And if I have to make the update (in my case removal of children) in another collection (lost since I have made entity->DTO->entity)?
Is it possible to get hibernat on the track again?


Im not sure exactly what you are asking, but I think you want to edit a different collection and put the stuff back in the hib collection.

Code:
List newList = process(hibObj.getHibList());
//process newList
//... [insert code here]
//now you need to put the objects back in the hib list
//(dont clear, add and retain):
hibObj.getHibList().addAll(newList);
hibObj.getHibList().retainAll(newList);


Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 5:22 pm 
Newbie

Joined: Mon Nov 14, 2005 7:07 am
Posts: 9
Thanx for yor patience!
Ill try to explain the problem.

I have two persistent objects; a Parent and a Child. The Paretn holds a Set of Child.
I execute a find() on the Parent and get the Parent and the Set of Child's.
The Parent and the Child'ren are then copied to a PartentTO and ChildTO respectively by using commons-beanutils with custom converters. In other words, the entities data are copied to transfer objects. These transfer objects are then passed to the web tier where they are changed. The specific scenario that do not work is when the web tier has removed on of the children from the parent, this is done on the ParentTO and ChildTO. The ParentTO with the Set of Child (where on child has been removed) is now converted back to entity objects, ie Parent and Child.
The Parent is then update()-ed and the problem is that the removed Child dont get removed in the DB. (cascading is set ok).
The reason being that the original hibernate generated collection of Child in the Parent entity has been broken by copying the collection to the TO and then back to the entity.

So what I need is a way to "restore" the original collection so that hibernate realizes that one child has been removed and therefore deletes it from the DB.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.