-->
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: How to use session.lock()
PostPosted: Fri Sep 12, 2003 10:40 am 
Regular
Regular

Joined: Tue Aug 26, 2003 3:34 pm
Posts: 54
Location: Farroupilha - Brasil
Hello,

I'm testing the hibernate lock funcionality but I get unexpected results ... The lock is valid only for the session that opened it ?


Code:
session = openSession();
obj = session.load(SomeClass.class, some_id);
session.lock(obj, LockMode.UPGRADE);


When I open the same object in another session I can do anything with the object !!!! Note that I'm not closing the session after load() ...

How lock works ???


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 10:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
LockMode.UPGRADE depends upon your database supporting SELECT ... FOR UPDATE.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 10:48 am 
Regular
Regular

Joined: Tue Aug 26, 2003 3:34 pm
Posts: 54
Location: Farroupilha - Brasil
All the lock types must be implemented for the database ?
I'm testing with HSQLDB ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 3:00 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 3:34 pm
Posts: 54
Location: Farroupilha - Brasil
Supose I'm using a database that support SELECT FOR UPDATE like PostgreSQL ....

When I lock the object and another user try to select it ... the second user don't get an error or exception reporting the lock, so I can't report the lock to user and the application will stay locked !!

Is possible to control when a lock occurs?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 3:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I have no idea what you are trying to communicate here. Hibernate LockModes are implemented on top of, and have exactly the same semantics as, the underlying SQL locks.

Hibernate never, ever blocks threads in Java. This is one reason why Hibernate is so scalable.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 4:01 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 3:34 pm
Posts: 54
Location: Farroupilha - Brasil
The lock works fine !!! I just want to tell user about the lock ...

"Hey user, you are trying to select a record that is been modified by another person !!! Whait or cancel ?"

I want to give user an option to NOT whait the lock finish ... understand?

Sorry, my english is weak..


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.