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
1
vote
1 answer

"Select for update" and update with pessimistic locking

I'm trying to implement pessimistic locking using select for update, as I want other threads to wait until the lock on the selected row is released. The part that I have understood is after going through multiple threads Spring JDBC select for…
ABC
  • 45
  • 2
  • 8
1
vote
1 answer

How to use "pessimistic" Couchbase locking with the C API?

This is incredibly frustrating... I'm using the Couchbase v3 C API, and I ran into a problem that would be solved perfectly by using their "pessimistic" locking. After much effort I believe I've finally figured out how to lock records using it (with…
Head Geek
  • 38,128
  • 22
  • 77
  • 87
1
vote
1 answer

Spring Data JPA - Pessimistic Locking Not Working

Using: Spring Boot 2.3.3, MySQL 5.7(currently via TestContainers), JUnit 5 I have a JpaRepository inside a Spring MVC application that has a method set to be @Lock(LockModeType.PESSIMISTIC_WRITE) and, while I do see the SELECT ... FOR UPDATE coming…
BtySgtMajor
  • 1,380
  • 10
  • 26
1
vote
1 answer

Deadlock in transaction with isolation level serializable

I was trying to understand how locking works with isolation levels. I have gone through this question but can not understand flow given blow Here i am starting two transactions in different terminals and reading same row in them. As i try to update…
1
vote
2 answers

Does Laravel's pessimistic lock effects its relationship model as well?

Lets say i have a query that gets a post model with its comment model. So the query should look something like this Post::with(['comments'])->get(); Now, i want to implement laravel's pessimistic locking like…
1
vote
1 answer

Getting "javax.persistence.TransactionRequiredException: no transaction is in progress" in Spring Boot Application

I am using JPA+Hibernate in my Spring Boot Application. My Service Method is as follows:- @Override public Employee createEmployee(Employee employeeModel) { logger.debug("entered the createEmployee method"); …
Manish
  • 1,274
  • 3
  • 22
  • 59
1
vote
2 answers

Deadlock with EF 6 entity update but not ExecuteSqlCommand

To handle concurrency in my database: Client A updates a row Client B tries to update the same row Client B needs to wait for Client A to commit his updates Both Client A & B instance are simulated and using this code: using (myEntities db = new…
1
vote
2 answers

Springboot Pessimistic Locking

I have trying to achieve row level locking in the postgres DB.Below is the sample code Repository : @Repository public interface DeploymentRepository extends JpaRepository { @Lock(LockModeType.PESSIMISTIC_WRITE) …
1
vote
1 answer

Pessimistic locking for many user requests

Is it possible to create a pessimistic lock that last for many user requests? I'm interested to see if is it possible in Java EE using Hibernate or PHP using Doctrine or Propel. I tried this by using Doctrine 2 but it is not possible, only at…
artaxerxe
  • 6,281
  • 21
  • 68
  • 106
1
vote
0 answers

How to avoid deadlocks in PessimisticLockScope.EXTENDED?

I’m creating a Java transfer money app that basically transfers money from one account to another. In a nutshell I have a Transfer entity that contains 3 properties: @ManyToOne OriginAccount, @ManyToOne TargetAccount and Amount. Account contains a…
1
vote
1 answer

PESSIMESTIC LOCK is not working with Spring Data accessing MySQL

I am using Spring Boot to build a scheduled-job data processing application. The main logic would be in a scheduled job that takes a batch of records and process them. I should be running 2 instances of the application that should not pick the same…
Moustafa Essa
  • 111
  • 1
  • 7
1
vote
0 answers

Alternative to ajax request in window.beforeunload, for releasing pessimistic lock

I have a web app that handles multi-user locking - a server-side lock is set when a record is opened for editing. The lock is released either when the form is submitted, or via an ajax request in window.beforeunload - so it is released when the user…
Matthew
  • 31
  • 1
  • 3
1
vote
1 answer

Concurrency Handling : Synchronization vs Multiple DB Calls

Imagine a MNC bank who wants to implement the account transfer API using core Java only and API would be used in multiple threaded environment, and maintain the consistency of account's amount all the time with no deadlock of-course I have two…
1
vote
1 answer

Laravel lockForUpdate + Transaction

We're using lockForUpdate like this: DB::beginTransaction(); try { $balance = UserBalance::where('user_id', 2) ->lockForUpdate() ->first(); $balance->usd += 100; $balance->save(); // A LOT…
1
vote
1 answer

How to lock on select and release lock after update is committed using spring?

I have started using spring from last few months and I have a question on transactions. I have a java method inside my spring batch job which first does a select operation to get first 100 rows with status as 'NOT COMPLETED' and does a update on the…