-->
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: Identifier of an Instance Altered
PostPosted: Mon Feb 09, 2004 12:22 pm 
Newbie

Joined: Tue Nov 04, 2003 4:20 pm
Posts: 13
Hi -
I have a case where an object has to be cloned with some minor changes though and recreated. In the process of doing so, I have encountered an issue which I have no idea why its happening. Lets consider I have a foo class with a bar attribute in it.

Code:
class Foo{
private Bar;
.......
}


CASE Doesnt WORK - Throws net.sf.hibernate.HibernateException: identifier of an instance of Foo altered from 2 to null
Code:
public void cloneMe(Foo old) throws Exception
{
// s -session
// t - transaction
t = s.beginTransaction();
Foo ret = (Foo) s.load(Foo.class, new Integer(2));
   
Foo newFoo = new Foo();
util.copyProps(ret, newFoo);
s.saveOrUpdate(newFoo);
t.commit();
}


But if I perform the same operation by loading Foo, closing the session and then pass the Foo to the clone operation, it works. Not sure why this is happening and since I would like the loading of the source and the save of the destination in the same transaction, can anybody please help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Check the implementation of util.copyProps().
Did you override equals method ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 09, 2004 1:30 pm 
Newbie

Joined: Tue Nov 04, 2003 4:20 pm
Posts: 13
I set the id of the target to null which should treat it as a new instance all together since my equals method checks against the id.

Thanks -


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.