Hibernate version:3.2.2.ga
Hi,
I would like to describe the following scenario where our database is empty and we are using the hibernate <version> in our mapping file
for our MyObj which consist of String,value and version :
section1
Code:
Session1.beginTransaction();
MyObj obj1 = new MyObj("obj1",1);
MyObj obj2 = new MyObj("obj2",1);
session1.saveOrUpdate(obj1);
session1.saveOrUpdate(obj2);
Session1.flush();
did not commit yet, and somewhere else in the code we are doing the following:
section2Code:
Session2.beginTransaction();
MyObj obj3= session.get(MyObj.class, "obj3");
if(obj3==null){
obj3 = new MyObj("obj3",1);
}else{
obj3.setMyValue("10");
}
MyObj obj1 = session.get(MyObj.class, "obj1");
if(obj1==null){
obj1 = new MyObj("obj1",1);
}else{
obj1.setMyValue("10");
}
session2.saveOrUpdate(obj3);
session2.saveOrUpdate(obj1);
session1.commit();
session2.flush();
this generates ConstraintViolationException
with the following message: A unique constraint violation on repository table during flush due to overlapping data between rules. Rolling back to the latest save point. This makes mush sense as we try to insert obj1 the second time.
After we get the exception we are executing
session2.clear() and executing section2
again The problem is that it manages to find obj3 in the database (it is not yet there as we got the exception and cleared the session - double checked it with toad :) );
After committing session2 we get the following database snapshot:
Code:
name myValue version
obj1 10 1
obj2 1 0
obj3 10 1 < -- > this one is wrong
Any suggestions are welcome.
Thanks,
Leon