I tried to save an object loaded in previous session
and hibernate throws nonUniqueObject exception
i have cleared the session (session.clear()) before updating
// in the first session
Cat cat = (Cat) firstSession.load(Cat.class, catId);
// in a higher tier of the application
cat.setMate(potentialMate);
// later, in a new session
secondSession.clear();
secondSession.update(cat); // update cat
but if I load a new instance (with the same identifier),
it works
// in the first session
Cat cat = (Cat) firstSession.load(Cat.class, catId);
// in a higher tier of the application
cat.setMate(potentialMate);
// later, in a new session
Cat cat1 = (Cat) firstSession.load(Cat.class, catId);
cat1.setMate(cat.getMate());
secondSession.update(cat1); // update cat
I dont use versioning.. and using hibernate 2.1.3
can anyone give me a hint ?
thanks
|