Questions tagged [pessimistic-locking]

Pessimistic locking is a strategy that will lock a database record, that is to be updated, for exclusive use until the update is complete.

Pessimistic locking is a strategy that will lock a database record, that is to be updated, for exclusive use until the update is complete. The database record is locked immediately when the lock is requested and it is then guaranteed that the database record will be updated. Unlike optimistic locking, great care must be taken in the application design to avoid deadlocks.

178 questions
2
votes
2 answers

How does when an entity with @Version annotatted field or property, optimistic lock enables automatically?

Recently I have been studying database transaction and one article quotes as following JPA provide automatic support of row versioning via the @Version annotation.When you have entity with @Version annotatted field or property, optimistic locking…
Bhupati Patel
  • 1,400
  • 2
  • 13
  • 18
2
votes
1 answer

optimistic locking optimistic concurrency control

As I learned that "optimistic locking" that sometimes referred "optimistic concurrency control", doesn't really have a lock. A typical implementation is CAS (Compare-And-Swap). So I wonder without locking, why this is still called "optimistic…
2
votes
1 answer

Alternative to pessimistic locking to objects that are constantly/concurrently updated

Currently we are developing a credit transaction system on Grails 2.4.4. We have a Credit model that holds the amount of credits of a User. class Credit { BigDecimal amount User user } Problem is the amount is constantly debited/credited as…
2
votes
1 answer

NHibernate - How to handle critical transaction in ASP.NET MVC action

I have an action that handle a critical transaction and I am not sure what would be the best way to handle the transaction. Here is a simplified example of what I would need to do: [HttpPost] public ActionResult BeginOrderProcess(Guid orderKey) { …
2
votes
2 answers

Hibernate Pessimistic Locking not working for Oracle Database?

I have a transactional method that could be called by multiple threads. To avoid StaleStateException when concurrent calls happen, I used pessimistic locking in hibernate, but it's not working as I expected and I still got the StaleStateException.…
David Z.
  • 243
  • 1
  • 5
  • 14
2
votes
1 answer

Exclusive locking

I would like to acquire exclusive locks either with mongo or couch db. Is it possible? (API reference would be helpful) Is it possible that exclusive lock gets released when client suddenly dies?
mpapec
  • 50,217
  • 8
  • 67
  • 127
2
votes
1 answer

Lock a entity at database level using Hibernate and HSQLDB

I have a system where I need to create a new instance of SomeEntity in a concurrent context, using another entity as "monitor" as exemplified below: //Begin transaction Monitor monitor = (Monitor) session.load(Monitor.class, monitor.getId(),…
2
votes
0 answers

jQuery: Pessimistic Record Locking when Browser/Computer goes into sleep mode?

I'm trying to debug an issue with some PHP/MySQL/jQuery code that handles pessimistic locking. It uses two fields: locking_user_id and locking_date_time. The locking is determined by an AJAX action to PHP/MySQL. The jQuery code below shows the…
jjwdesign
  • 3,272
  • 8
  • 41
  • 66
2
votes
2 answers

How to rollback/timeout “select for update” locks in Oracle?

Our app is mostly using optimistic locking using Hibernate’ s versioning support. We are planning to implement pessimistic locking in one particular scenario. I don’t have much experience with pessimistic locking so please excuse if this question…
haps10
  • 3,496
  • 6
  • 32
  • 38
2
votes
1 answer

Architecture for editing hierarchy with mutlipe levels of nodes with multiple users

I am building a module to edit a hierarchy of nodes. You can think of it as a very large directory structure with many levels of nested directories and files. The nodes for the hierarchy are stored in a relational database table. The only…
JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
2
votes
3 answers

In SQL Server 2005 and 2008, how to tell I'm using pessimistic concurrency model or optimistic one?

I know SQL Server 2000 has a pessimistic concurrency model. And the optimistic model was added in SQL Server 2005. So how do I tell whether I'm using the pessimistic concurrency model or the optimistic one in SQL Server 2005 and 2008? Thanks.
Just a learner
  • 26,690
  • 50
  • 155
  • 234
1
vote
1 answer

CakePHP and pessimistic locking: database vs cache

I've implemented a pessimistic locking in my CakePHP application, shared between different Controllers. Basically, when a page is accessed a record is written into a table, indicating that that entry of that model is being edited by that user, with…
entropid
  • 6,130
  • 5
  • 32
  • 45
1
vote
1 answer

Avoid StaleObjectStateException when deleting entity

I have 2 concurrent threads that at the same time enter a (Spring) transaction service. Using Hibernate, the service method loads some entities, processes those, finds one and deletes it from the DB. The pseudo code is as…
1
vote
0 answers

Hibernate PessimisticLockException in multi-threading Spring Boot application with MySQL

I have a Spring Boot web application with Hibernate that is launching several threads concurrently to process some jobs in parallel using a queue policy. The application is failing randomly with this…
Daniel
  • 49
  • 1
  • 1
  • 10
1
vote
2 answers

How to resolve PessimisticLockingFailureException

I'm frequently getting PessimisticLockingFailureException. I gone through the https://docs.jboss.org/hibernate/orm/4.0/devguide/en-US/html/ch05.html and understood that we need to mention the lock explicitly in the code. Where as in my code, I…
Hemanth
  • 101
  • 1
  • 4