-->
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: different object with the same identifier value
PostPosted: Fri Jun 20, 2008 3:16 pm 
Newbie

Joined: Fri Feb 15, 2008 4:35 pm
Posts: 6
Hi
I have a problem and I need an idea to solve it
I need to clon an object, change it and save the original object and update the clon, but when I do this Hibernate throws an exception like this: a different object with the same identifier value was already associated with the session
I understand this exception but I don't know how to do this,
please any idea will be helpful


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 21, 2008 11:01 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Hi,

I think that after cloning your object you have to clear the ID / primary key attribute of the clone before you persist it. When creating the clone it is not known to Hibernate, and you can freely manipulate it's ID attribute.

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 23, 2008 10:24 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I've done this before.

What you need to do is an eviction. Take the object that was loaded into Hibernate and evict it. The object becomes detached. Set the primary key or id of that evicted object to zero or null. Then, you can add the object back to the Hibernate Session and it will be treated as a new instance and saved with a new primary key when the transaction is comitted to the database.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.