Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate - How to restrict the concurrent read of the record by multiple users?

We are using Hibernate 3.6.0. We have requirement of retrieve next available record from the table. How do we control retrieving same record by multiple concurrent users. We need to read the next available record and update the status on column (kind of lock) to avoid next user retrieving the same record. We added Version column on the table (Optimistic lock), but it seems controlling on update.

What is the best solution in Hibernate to achieve this?

Thanks in advance. Venkat

like image 764
user686784 Avatar asked Apr 01 '11 21:04

user686784


1 Answers

Have you tried locking the record in question? Hibernate supports pessimistic locking (SELECT FOR UPDATE), look at the documentation.

You might also try optimistic locking, it kind of depends on the level of concurrency you expect.

like image 177
Tomasz Nurkiewicz Avatar answered Oct 24 '22 05:10

Tomasz Nurkiewicz