-->
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.  [ 6 posts ] 
Author Message
 Post subject: Strategy for LOCK
PostPosted: Tue Jun 15, 2004 8:37 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
In my project (an client server application, not a web app), different instances of the client, each having its own hibernate Session, may access the same object for update.

The problem is that setting a lock on an object is Session-wide, it does not reach the DB level. hence two different sessions have two different lock level

How do I set a lock that forbids access to an object even in other sessions ? Is there a way to raise the lock level to DB isolation system, or do I have to develop my own lock system ?

Does anyone have example of this that he would share with me

regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 3:28 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate never lock at the middle tier level. It always delegate to the DB locking system.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 4:45 am 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
Yes, but the problem is that isolation is Session-wide. ie another Session is not aware of one's lock.

When I set a Lock at level UPGRADE, another Session is able to read a record, which is normal, but as it is not aware that the first one has made a SELECT ... FOR UPDATE. Which means that it will wait to commit its changes until the first one has released its lock. Which will happen when the first one will have committed its own changes, and thus, the second Session will have its changes rejected (StaleObjectStateException - which is normal and expected).

And I didn't find any trace of a way to set a timeout on Session 2's commit. It just waits - like forever - until it's rejected.

So what is the interest of letting user change the lock level ?

As I understand it, the locking system of Hibernate is just an optimistic lock build for internal usage of Hibernate. If the user has to set locks in the application, he must build his own system from scratch.

Am I completly mistaking ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can access the JDBC connexion using session.connection() and do what you want, I guess
There is a lock no wait if you use Oracle.
The LockMode is independant from the Hibernate optimistic locking.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 12:32 pm 
Newbie

Joined: Fri May 07, 2004 6:05 am
Posts: 17
I'll try that

But one thing is for sure, there is a conflict here, because changing the LockLevel in a Session interfers with other users' Sessions


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 12:35 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You don't change the TX isolation level, you lock an object or not, this is different

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.