-->
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.  [ 3 posts ] 
Author Message
 Post subject: Delete and insert in the same session?
PostPosted: Thu Jun 10, 2010 7:00 am 
Newbie

Joined: Thu Jun 10, 2010 2:38 am
Posts: 5
Hi,
I have a method that updates the object X (Train with passengers) that is a parent to its children (passengers). When I update object X (Train) I execute session.saveOrUpdate(plane) for object X (this successfully updates object X), then I want to delete all of its old children and re-insert the new ones (as the children could have changed in meantime). Most of the new children will have the same id (primary key) as the old ones.
When I do it in one session, Hibernate complaints that two different objects with the same id are associated with the same session – fair enough – the deleted one is probably still in the cache, so the new one is treated as the different object with the same id.
My question is, how to tell hibernate to forget about that ones I have deleted (wipe them out of the cache) and re-insert the new ones (in the same session) – which would also work for new children, that did not exist previously.
Any ideas how to do it?
Very appreciated,
Janusz


Top
 Profile  
 
 Post subject: Re: Delete and insert in the same session?
PostPosted: Thu Jun 10, 2010 8:21 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
try session.clear


Top
 Profile  
 
 Post subject: Re: Delete and insert in the same session?
PostPosted: Fri Jun 11, 2010 4:39 am 
Newbie

Joined: Thu Jun 10, 2010 2:38 am
Posts: 5
This will cancel all my changes though - I don't want that


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