-->
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: Invalid LockMode - Urgent!
PostPosted: Mon Oct 24, 2005 10:52 pm 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Hi... trying to acquire lock on an object:

Code:
trx = sess.BeginTransaction()

invitem = sess.Load(...)
[b]sess.Lock(invitem, LockMode.Write)[/b] 'Hey! [b]Exception[/b] here!

req = sess.Load(...)
If invitem.availAmount > req.reqFund Then
req.Amount = updated_amount
inv.availAmount = inv.availAmount - req.Amount

sess.Flush()
End If

trx.Commit()



Quote:
Inner Exception: NHibernate.HibernateException: Invalid lock mode for Lock()
at NHibernate.Impl.SessionImpl.Lock(Object obj, LockMode lockMode)
at


Any ... idea how I can resolve this? I need to acquire write lock on invitem... urgent. Thanks in advance!


Top
 Profile  
 
 Post subject: WRITE Lock
PostPosted: Tue Oct 25, 2005 12:23 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
In NHibernate doc for LockMode.Write, it actually says:

Quote:
This is not a valid mode for Load() or Lock().


But how can I specify/force a WRITE lock on the object instance?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 5:34 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
LockMode.Upgrade should work.


Top
 Profile  
 
 Post subject: no... Lock isn't acquire until Update is flushed.
PostPosted: Thu Oct 27, 2005 1:13 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Hi sergey, thanks for the comment but I step thru the code, it occur to me that lock (I assume UPDATE lock) on the invitem is NOT acquired until "sess.Update(invreqitem)" (I verify this by running Query Analyzer and try to update invitem concurrently while I step thru the following code segment):

Code:
trx = sess.BeginTransaction()
...
...
invitem = LookupInventoryItem(item_id, True, sess)
sess.Lock(invitem, LockMode.UpgradeNoWait)
...
...
'make a few checks here, example:
'    ref_invitem.AvailBalance > invreqitem.ReqFund
'Therefore it is necessary for me to "Lock":
'a. invitem - from beginning of this code segment/transaction.
'b. invreqitem
...
...
sess.Update(invreqitem)
sess.Flush() 'That's when lock is acquired?!

...
...
trx.Commit()


Help!


Top
 Profile  
 
 Post subject: I found a way (not very elegant) to coerce ...
PostPosted: Thu Oct 27, 2005 2:03 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
I found a way to coerce NHibernate to acquire lock:
Code:
trx = sess.BeginTransaction()
...
...
invitem = LookupInventoryItem(item_id, True, sess)
invitem.Remarks = "Must do dummy update here or no locking!"
sess.Update(invitem)
sess.Flush()
...
...
'make a few checks here, example:
'    ref_invitem.AvailBalance > invreqitem.ReqFund
'Therefore it is necessary for me to "Lock":
'a. invitem - from beginning of this code segment/transaction.
'b. invreqitem
...
...
sess.Update(invreqitem)
sess.Flush() 'That's when lock is acquired?!

...
...
trx.Commit()


Top
 Profile  
 
 Post subject: Any way to acquire eXclusive lock besides a dummy update?
PostPosted: Thu Nov 03, 2005 10:23 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
So, guys, is there any way to acquire eXclusive lock on a record without first performing a dummy update on the record?

Thanks in advance.


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.