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
0
votes
1 answer

Pessimistic lock in MySQL not always working on application running in multiple instances

Hello Im trying to understand an issue related to pessimistic locks when running 3 instances of my application. The application has, among other stuffs, a spring schedule which runs every 3 hours and I need the business logic inside the…
0
votes
1 answer

Hibernate: Scope of pessimistic locks within transaction

I am using Hibernate for ORM for a game server and just switched from session/transaction per unit of work to session/transaction per request. Since multiple transactions may conflict with each other I am using pessimistic locking. The problem is…
0
votes
4 answers

Can we prevent reading of rows from db table that are exclusively locked?

I have a table EMPLOYEE with the following columns in my MySQL (innoDB) database, internal_employee_id (auto incrementing PK) external_employee_id name gender exported (boolean field) In a distributed system I want to ensure that multiple…
0
votes
1 answer

Deadlock on Concurrent request with pessimistic read spring data JPA

Table Details : Scenario : I am maintaining a table to store login information such as how many times the user has tried to login, how many failed attempts and how many times the captcha has been generated for a specific user. These are identified…
0
votes
1 answer

Spring Data JPA - Best Way to Update Concurrently Accessed "Total" Field

(Using Spring Boot 2.3.3 w/ MySQL 8.0.) Let's say I have an Account entity that contains a total field, and one of those account entities represents some kind of master account. I.e. that master account has its total field updated by almost every…
0
votes
0 answers

Entity Framework BeginTransaction with Isolation level but no working

I'm building database by using mysql connector with EF6. Way to handling concurrency updates happens. Client A updates row Client B come in updates same row Client B need to wait Client A commit his updates. Codes: using (myEntities db = new…
0
votes
0 answers

Laravel pessimistic locking locks entire table instead of a single row

Laravel Version: 7.15 PHP Version: 7.4.6 Database Driver & Version: MariaDB 10.4.11 Below code is going to return array response for each invoices. Once action method called for id=1 it takes 20 sec to get committed. When the same method called for…
0
votes
1 answer

How does pessimistic locking work across requests in Rails?

If a user is editing a resource with pessimistic lock no one else can edit the resource until the editing user saves his changes. Now to my question, what happens when the editing user did not save his changes but clicks on the browser back button…
Jul
  • 141
  • 13
0
votes
1 answer

Why Pessimistic triggers a deadlock

I'm trying to undestand Pessimistic Lock with a simple example of Bank Money Transfer. I believe this statements can lead to a Deadlock BEGIN TRANSACTION UPDATE BankAccount SET balance = balance - amount where id = 123; UPDATE BankAccount SET…
Mssm
  • 717
  • 11
  • 29
0
votes
2 answers

Grails Pessimistic locking with executeUpdate()

I can't find any info on how to use pessimistic locking with an executeUpdate() command in grails. Is this possible? [Update] As per Burt's suggestion, this is the resulting query I have. Note that I have used the deprecated UPGRADE instead…
Abe
  • 8,623
  • 10
  • 50
  • 74
0
votes
1 answer

Pessimistic in CosmosDB

I concern how to behave in case multi-user system facing concurrent updates. Basically we are using a stored procedure to implement our logic. I knew that there is a built-in optimistic concurrency control by ETag and using a HTTP 412 response…
0
votes
1 answer

Hibernate PESSIMISTIC_WRITE not locking db and returning oldValue

I am using "Postgres" database and pessimistic_locking for locking database row. I have the following code @Transactional doProcess(int id, int quantity){ Article article = lockArticle(id); modifyArticle(article, quantity); } This is…
0
votes
1 answer

Is there any way to make both pessimistic and optimistic locking working in Hibernate

I have an entity like this @Entity @Table(name = "ACC_ACCOUNT_INFO") @Getter @Setter public class AccountInfoEntity implements Serializable { @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =…
mystery
  • 875
  • 6
  • 16
0
votes
1 answer

Would pessimistic lock has cascade effect?

Here is my data structure. @Entity public class JobEntity { @Id private Long id; private String name; @OneToMany(fetch = FetchType.EAGER,cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, mappedBy =…
Man Shen
  • 401
  • 2
  • 16
0
votes
1 answer

how to implement pessimistic locking in long conversation with user think time in between, using hibernate as example?

as pessimistic lock can only apply on a single database transaction. and keep the database transaction open during user think time, with locks held in the database is thought as anti-pattern, then what is the correct way to implement pessimistic…
user1169587
  • 1,104
  • 2
  • 17
  • 34