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
0 answers

Find and update with pessimistic_write lock could not prevent from optimistic lock failure?

I've tried to find and update one record using pessimistic_write lock, like below, transactionService.executeTransaction(() -> { Entity newEntity = em.find(entityClass, id, LockModeType.PESSIMISTIC_WRITE); newEntity =…
Man Shen
  • 401
  • 2
  • 16
1
vote
1 answer

REPEATABLE_READ isolation level with PESSIMISTIC_WRITE lock

Right now I am preventing several users from several instances to access the same row of my database table with a PESSIMISTIC_WRITE lock. The transaction which locks the row has the default isolation level set which is REPEATABLE_READ. Under the…
1
vote
0 answers

Doctrine isLocked method

Is there a way to check if an entity is locked with doctrine ? In my case, I need to know from an EventListener if a related entity has been locked in current transaction to prevent logic errors. Something like this would be great : //…
1
vote
0 answers

Rails transaction deadlock or something

I have User, Order, Contest and Position models in my Rails app. There are many-to-many relationship between User and Order and one-to-many between Position and Order, User and Contest. I have order processor service with execute method which…
1
vote
2 answers

entity framework 6 and pessimistic concurrency

I'm working on a project to gradually phase out a legacy application. In the proces, as a temporary solution we integrate with the legacy application using the database. The legacy application uses transactions with serializable isolation…
1
vote
1 answer

NHibernate - pessimistic locking not working

Follow up of this other question. I'm trying to implement pessimistic locking for a concurrency issue as I described in the question above (please, feel free to add to that one). But it's not working for me. I do a very simple test: I have two…
Razzie
  • 30,834
  • 11
  • 63
  • 78
1
vote
0 answers

Entity Framework - Transaction Scope pessimistic locking

I've been trying to implement pessimistic locking of EF contexts using Transaction Scope. Models: User Room ICollection Users int Capacity Controller: public void List() { using(var context = new MyDBContext()) { //…
1
vote
1 answer

Spring Database Lock: Need help in understanding the condition for database deadlock

I am using Spring-Data-Jpa and using @Lock annotation(PESSIMISTIC_WRITE) for taking database(Oracle) locks. I need help in understanding that whether the following scenario can lead to a database dead lock. Transaction 1(PROPAGATION_REQUIRES_NEW,…
1
vote
0 answers

JPA with DB2 - Pessimistic locking with timeout

I do pessimistic locking on an entity with JPA. The db is DB2 v10.x, JPA 2.0 over Hibernate 4.x. I don't want to wait until the lock is available (it is locked by a long-time running process, keeping the lock on the entity for several minutes). I…
spi
  • 626
  • 4
  • 19
1
vote
0 answers

Executing same select for update without order by with multiple results in different transactions causing deadlocks

Transaction A: select * from table_a where field_a = 'A' for update; Transaction B: select * from table_a where field_a = 'A' for update; If these transactions are ran at about the same time, can it cause a deadlock? The queries are expected to…
froi
  • 7,268
  • 5
  • 40
  • 78
1
vote
1 answer

Physical lock on DB rows obtained from a JPA PESSIMISTIC lock

According to the JPA 2.1 specification... The lock modes PESSIMISTIC_READ, PESSIMISTIC_WRITE, and PESSIMISTIC_FORCE_INCREMENT are used to immediately obtain long-term database locks. I assume a pessimistic lock will always trigger a SELECT…
mika
  • 2,495
  • 22
  • 30
1
vote
1 answer

Pessimistic locking fails

I have the following code in my controller: Item.transaction do item = JobDistribution.lock(true).find(params[:id]) item.update_attributes(status: JobDistribution.statuses[:processing]) respond_to do |format| format.json { render :json =>…
bl0b
  • 926
  • 3
  • 13
  • 30
1
vote
1 answer

Hibernate pessimistic locking do not work with polymorphic query

I have a following class hierarchy: @Entity @Table(name = "BaseThing") @Inheritance(strategy = InheritanceType.JOINED) public abstract class BaseThing implements Serializable { @Id @Column(name = "id", nullable = false) private Long…
eitann
  • 1,203
  • 10
  • 23
1
vote
2 answers

Pessimistic locking is not working with Query API

List esns=session.createQuery("from Pool e where e.status=:status "+ "order by uuid asc") .setString("status", "AVAILABLE") .setMaxResults(n) …
Reddy
  • 8,737
  • 11
  • 55
  • 73
1
vote
1 answer

How Hazelcasts Entry Processor differs from Pessimistic (Explicit) Locking?

Internally entry processor also perform the lock and unlock on the key as pessimistic locking. But entry processor is more efficient as compared to pessimistic locking. Whats the difference between these to?