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.