-->
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.  [ 4 posts ] 
Author Message
 Post subject: Explicitely release lock
PostPosted: Wed Jan 17, 2007 11:56 am 
Newbie

Joined: Wed Jan 17, 2007 11:50 am
Posts: 10
Hello,

I have acquired a lock on an object using Session.lock(obj, LockMode.UPGRADE) to prevent other transactions from writing to this object.

Is it possible to release this lock explicitely *before* the end of the transaction? I have tried Session.lock(obj, LockMode.NONE), but that seems to do nothing.

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 3:00 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Uhm, if you obtain a row-level exclusive write lock in the database, you do so because you say "I want to make sure that nobody writes to this while I do". If you would be able to (you can't) release the lock before the end of your transaction, the whole exercise would be futile.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 5:33 am 
Newbie

Joined: Wed Jan 17, 2007 11:50 am
Posts: 10
Thank you for the quick reply.

What I wanted to do is this: I want to read an object graph (a parent object plus several connected objects) in a consistent state, i.e. once I begin reading the object graph no other transaction should be able to write to any of those objects until I finish reading them.

The idea was to set a lock on the parent object, read the objects, then release the lock.

Any transaction that wants to write any object of this graph has to lock the parent object first. That way I would prevent any object of the graph from being modified while another transaction is reading.

One more question about not being able to release locks: is this a restriction of Hibernate or is this generally impossible on the database side?

Maybe a nested transaction would do the trick - then the lock would be released at the end of the inner transaction, wouldn't it?

Thanks for any more insights.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 8:50 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
SQL can't do it and also Java (as in JDBC and JTA) doesn't support nested transactions. Some DBMS might have a proprietary SQL command for lock release though. Keep in mind that many DBMS already provide repeatable read, even if they are in read committed mode (Oracle, PostgreSQL, SQL Server 2005, basically any MVCC-capable database).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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