Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 843681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:10:01+00:00 2026-05-15T06:10:01+00:00

I am retrieving a list of objects in hibernate using Criteria API. However I

  • 0

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();

Update: I am performing an update after this statement, so that I would like both threads to read different rows or at least second thread should wait till first thread completes with the transaction and leaves the lock.

And the hibernate generated query is below.

Hibernate: select this_.id as id1_0_, this_.name as name1_0_, 
this_.orderitem_id as orderitem3_1_0_, this_.status as status1_0_, 
this_.store as store1_0_, this_.vendor as vendor1_0_, this_.version as version1_0_ 
from reddy_pool this_ 
where this_.status=? and and this_.name=? order by this_.id asc limit ?

Update: It seems a bug in 3.5.2 version as Pascal Thivent (Thanks a lot Pascal) mentioned, I have joined as member and watching the issue. Hopefully it will be included in the next release.

However I tried using another approach here with session.buildLockRequest()… but I couldn’t quite figure out how to use it and using below code is not having any effect at all.

for (int i=0; i < n; i++)
    session.buildLockRequest(LockOptions.UPGRADE).lock(esns.get(i));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:10:02+00:00Added an answer on May 15, 2026 at 6:10 am

    What version of Hibernate are you using? Could this be HHH-5275? Are you sure that the FOR UPDATE statement isn’t generated? Can you show the generated SQL?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code, I'm retrieving a list of Integers from a DB and
I am using Hibernate and getting Exception in thread main org.hibernate.ObjectNotFoundException: No row with
I am retrieving a list of objects from json url and displaying it like
I need to return a list of objects from a restful webservice. each object
I need to store different objects in IsolatedStorage and i'm using IsolatedStorageSettings class to
I'm retrieving an IEnumerable list of properties via following code: BindingFlags bindingFlag = BindingFlags.Instance
OK so I am retrieving fullname from web page to filter customer list and
I'm retrieving data from a MySQL table and displaying it on a webpage using
I'm retrieving a signed int from a SQL Server database and need to convert
I am unit testing an ICustomerRepository interface used for retrieving objects of type Customer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.