-->
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.  [ 7 posts ] 
Author Message
 Post subject: LockMode problem
PostPosted: Thu Aug 28, 2003 9:09 pm 
Newbie

Joined: Thu Aug 28, 2003 8:41 pm
Posts: 17
i think this is a very common case:

in a transaction,load an object from database,check some attributes of the object to determine whether you can update the object.

try{
tx=session.beginTransaction();
Foo f=(Foo)session.load(Foo.class,id);
if(f.getSomeFlag()){
throw new YouCannotUpdateFooException();
}else{
f.setSomeAttr("someAttr");
}

tx.commit();
}catch(Exception e){
if(tx!=null)
tx.rollback();
throw e;
}

(the isolation level of my database is greater than repeatable-read.)
i don't know in which LockMode should i load (Foo f),LockMode.UPGRADE?
or just the default LockMode.NONE?
(if session.load() load the object from the database,i think the default LockMode.NONE is ok,but it may load the object from cache)

and the Hibernate api doc say that you should spend much time worrying about locking except you are an "advanced" users.

thanks a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 9:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hmmmmm. This is interesting. Currently the lockmode doesn't affect whether we hit the cache. If the object is in the cache already, it will just lock() it after pulling it from the cache (in the case of versioned data, lock() does a version check).

However, I can see a really strong argument that for lockMode > LockMode.NONE, we should ignore the process-level cache altogether. I think I will make that change.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 10:01 pm 
Newbie

Joined: Thu Aug 28, 2003 8:41 pm
Posts: 17
Thanks,Gavin.

i must ensure that between i checking the flag and updating the object,
other threads can not change the status of the object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 5:00 am 
Newbie

Joined: Thu Aug 28, 2003 8:41 pm
Posts: 17
can i add a <version> property and catch the StaleObjectStateException to avoid concurrent update?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 5:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Whaddayamean "catch"?


StaleObjectStateException occurs during flush() and is unrecoverable.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 5:13 am 
Newbie

Joined: Thu Aug 28, 2003 8:41 pm
Posts: 17
gavin wrote:
Whaddayamean "catch"?


StaleObjectStateException occurs during flush() and is unrecoverable.


I think a StaleObjectStateException means concurrent update between checking the flag and updating the object, so I can try again until
no StaleObjectStateException thrown.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 9:33 pm 
Newbie

Joined: Thu Aug 28, 2003 8:41 pm
Posts: 17
Anyone help me?

Thanks.


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

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.