-->
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: Can I delete and re-add object with the same id
PostPosted: Fri Jun 11, 2010 1:25 am 
Newbie

Joined: Thu Jun 10, 2010 2:38 am
Posts: 5
When I delete an object and re-add new one with the same id (within the same session) I get NonUniqueObjectException. How can I tell hibernate to remove the deleted object from it’s cache or wherever the old object is kept.
Regards,
Janusz


Top
 Profile  
 
 Post subject: Re: Can I delete and re-add object with the same id
PostPosted: Mon Jun 14, 2010 3:01 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
try
Code:
session.clear


or

Code:
session.evict(yourobject)


Top
 Profile  
 
 Post subject: Re: Can I delete and re-add object with the same id
PostPosted: Mon Jun 14, 2010 8:24 pm 
Newbie

Joined: Thu Jun 10, 2010 2:38 am
Posts: 5
But I also want to keep new added objects and as far as I know clear or evict would remove them as well.
Regards,
Janusz


Top
 Profile  
 
 Post subject: Re: Can I delete and re-add object with the same id
PostPosted: Mon Jun 21, 2010 3:58 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
If you call session.evict(yourobject) on your old deleted object,
then you keep the new added objects in persistence context.
Where's the problem?


Top
 Profile  
 
 Post subject: Re: Can I delete and re-add object with the same id
PostPosted: Mon Jun 21, 2010 7:41 pm 
Newbie

Joined: Thu Jun 10, 2010 2:38 am
Posts: 5
Do I have to keep deleted objects in an array and when I add new object with the same id (key) then I evict it before I do saveOrUpdate?
(Just small explanation - I always delete all objects at the start, then I create and add new once – some of them might be genuinely new ones (different primary key) and some might be with the same primary key as the old one (the one that I just deleted - but they have not been removed from cache).


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