I don't understand your answer?
Simple sample without showing session creation and the transaction management !
s1.save(o1);
o2 = s2.load(o1.getId());
o1.setNewValue(...);
s1.saveOrUpdate(o1) ok!, now database has a new version
o2.setNewValue(...);
s2.saveOrUpdate(o2) here I got the stale exception
To solve the collison I call :
s2.evict(o2);
o3 = s2.load(o2.getId()); here I got the stale exception object
I don't no why I got the stale exception, because I have released the object o2 from s2. So o2 is detached and doe'snt exist in the session s2.
|