-->
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.  [ 1 post ] 
Author Message
 Post subject: Object database persistency / concurrency problem
PostPosted: Thu Jun 26, 2008 4:40 am 
Newbie

Joined: Thu Jun 26, 2008 3:37 am
Posts: 1
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:

section2
Code:
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.