-->
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.  [ 2 posts ] 
Author Message
 Post subject: lock with NOWAIT waits
PostPosted: Tue Aug 11, 2009 10:02 pm 
Newbie

Joined: Mon Sep 24, 2007 8:11 am
Posts: 16
I am using Hibernate to connect to a Postgres DB on Windows. I am using optimistic locking in my app, but there is one object for which I need pessimistic locking. I am trying to use the code below:

Code:
public boolean getLock(Object o)
try
{
    session.lock(o, UPGRADE_NOWAIT);
    return true;
}
catch (Throwable t)
{
    LOG.error("Object is already locked");
    return false;
}


I thought that the session.lock() would throw an exception if the persistent object was already locked. But when I run my tests, the calls to session.lock() wait until the other code thread commits the transaction that got the original lock on the object.
Any clue to what I might be doing wrong, or what I'm misunderstanding?

Thanks,


Top
 Profile  
 
 Post subject: Re: lock with NOWAIT waits
PostPosted: Wed Aug 12, 2009 10:49 am 
Newbie

Joined: Mon Sep 24, 2007 8:11 am
Posts: 16
BTW - I see the same results using MsSQL as the DB - the session.lock() with UPGRADE_NOWAIT call waits until the transaction that originally locked the object completes. As I said, my understanding of that lock mode is that it should throw and exception if the object has been locked by a separate transaction.


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