-->
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.  [ 4 posts ] 
Author Message
 Post subject: Insert copy of record
PostPosted: Fri Jan 29, 2010 9:02 pm 
Newbie

Joined: Mon Sep 07, 2009 4:20 pm
Posts: 12
Item c = (Item) hibernateSession.load(Item.class, ItemPk);

c.set...();
c.set...();
c.set...();

tx = hibernateSession.beginTransaction();
hibernateSession.save(il);
tx.commit();

This fails with "identifier of an instance of Item was altered from ItemPk..."

And that's what I actually want to do... I want to fetch an existing record from the DB, modify some of it's values, and insert it as a new one.

How could I do that with hibernate?


Top
 Profile  
 
 Post subject: Re: Insert copy of record
PostPosted: Mon Feb 01, 2010 2:47 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
The instance is "connected" to the hibernateSession. Call evict() to detache the entity and set the identifier to null. After that call save().


Top
 Profile  
 
 Post subject: Re: Insert copy of record
PostPosted: Fri Feb 05, 2010 6:45 am 
Newbie

Joined: Mon Sep 07, 2009 4:20 pm
Posts: 12
Thanks, that worked beautifully


Top
 Profile  
 
 Post subject: Re: Insert copy of record
PostPosted: Fri Feb 05, 2010 8:26 am 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
And how can I evict an object that is not connected to the session, that is, it's used by other session but it has undesired identifier from the first session?


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