-->
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: a question about "Lock"
PostPosted: Mon Mar 08, 2004 4:22 am 
Newbie

Joined: Mon Mar 08, 2004 3:59 am
Posts: 2
Dear all,


I have a question about "setLockMode" for Query
some codes as following....

===================================
Transaction tx= session.beginTransaction();
Query q = session.createQuery(" from Add as addr");
q.setLockMode("addr", LockMode.UPGRADE);
result = q.list();
......
tx.commit()
......
===================================


logically,
When the code "q.list()" is executed, hibernate will connect to the database(DB2) and fetch records using "select ... for update"
and, all records will be locked.



But I failed....
I set "q.list()" as a breakpoint.

concurrently,
run a prog to update(or insert) data
It still works.... (shock)


anybody can tell me what's wrong.....


Top
 Profile  
 
 Post subject: Re: a question about "Lock"
PostPosted: Thu Mar 11, 2004 2:22 am 
Newbie

Joined: Thu Mar 11, 2004 1:33 am
Posts: 5
Location: Taipei, Taiwan
Well, this will work:

aEmp = (Employee)session.load(Employee.class, aPK);
session.lock(aEmp, LockMode.UPGRADE);
session.refresh(aEmp);
Transaction tx = session.beginTransaction();
aEmp.setXxx(xxx);
...
tx.commit();

To refresh() after lock() will let the 2nd concurrent thread re-read database after the blocking of lock is released. I tested it in the ThreadLocal pattern where there are separate Hibernate sessions maintaining different copies of PO relative to the same db record.
Also, Oracle9 dialect is used to ensure DB native lock scheme.

I think the main issue is that both session.lock() and session.load() with a nontrivial LockMode lock the record AFTER the data is retrieved. There is no method in Hibernate Session to lock BEFORE retrieve.


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.