How to specify pessimistic lock with Criteria API?
Posted
by Reddy
on Stack Overflow
See other posts from Stack Overflow
or by Reddy
Published on 2010-06-12T11:24:32Z
Indexed on
2010/06/12
11:33 UTC
Read the original article
Hit count: 277
hibernate
|criteria-api
I am retrieving a list of objects in hibernate using Criteria API. However I need lock on those objects as another thread executing at the same time will get the exact objects and only one of the thread will succeed in absence of a pessimistic lock.
I tried like below, but it is not working.
List esns=session.createCriteria(Reddy_Pool.class)
.add(Restrictions.eq("status", "AVAILABLE"))
.add(Restrictions.eq("name", "REDDY2"))
.addOrder(Order.asc("id"))
.setMaxResults(n)
.setLockMode(LockMode.PESSIMISTIC_WRITE) //not working at all
.list();
© Stack Overflow or respective owner