Skip to main content

All Questions

1 vote
0 answers
46 views

How to setup optimistic locking for overlapping datetime?

I am trying to make a booking system, where users can book a booking at a location for a certain time period. The problem I am having is, 2 entries that happen at the same time and overlap in the time ...
user26020733's user avatar
-1 votes
1 answer
96 views

Optimistic and Pessimistic Locking in JPA vs Isolation level

Why do we need locking if we can easily change for instance isolation level from READ_COMMITED to REPEATABLE_READ or SERIALIZABLE. Do we win a lot of in perfomance? Should we up isolation level only ...
Denis Rozhko's user avatar
1 vote
1 answer
1k views

How to implement optimistic locking from scratch?

I'm writing to files and I have a very un-contentious workload. However, there is a small chance of a race condition. I want to avoid using a database at this stage and implement optimistic locking on ...
david_adler's user avatar
1 vote
2 answers
517 views

Optimistic Locking: multiple request to save one data

stack blize. <div class="container"> <input type="text" [(ngModel)]="data.name" (blur)="onBlur()"> <br> <input type="checkbox" [(ngModel)]="data.aa" (ngModelChange)="...
Liem's user avatar
  • 456
4 votes
3 answers
7k views

What is a real world example where you would choose to use pessimistic locking?

I have read many articles on when to use Optimistic vs. Pessimistic locking and my basic understanding is : Optimistic locking is more scalable so probably use this if possible Use pessimistic ...
lmo523's user avatar
  • 489
1 vote
0 answers
116 views

Couchbase storing CAS in object

I am developing application using Couchbase and I am trying to implement optimistic locking. I want to store CAS in my stored object, is there a way to add field in JSON so It will be automaticly ...
Tomasz Bawor's user avatar
  • 1,667
0 votes
1 answer
704 views

hibernate optimistic lock mechanism

I am so curious about the hibernate optimistic lock (dedicated version way), I checked hibernate source code which tells that it checks version before current transaction commits, but if there is ...
user2015063's user avatar
1 vote
2 answers
3k views

Is there a way to avoid HibernateOptimisticLockingFailureException?

i have a persistent hibernate managed @entity Obj in Hibernate, which has fields id, fieldA, and fieldB, among others. In some class i have two @Transactional methods, updateA() and updateB(). ...
inor's user avatar
  • 2,846
1 vote
1 answer
5k views

Pessimistic vs. optimistic concurrency control

I have a question about pessimistic versus optimistic locking. Everybody says that "Optimistic locking is used when you don't expect many collisions.", for example: which concurrency control is more ...
user1255553's user avatar
30 votes
2 answers
7k views

How are locking mechanisms (Pessimistic/Optimistic) related to database transaction isolation levels?

I am writing a web application where two different users can update a list of things, to do list, for example. I have come to realize that, optimistic locking mechanism works best since I don't expect ...
Abhishek Shukla Ravishankara's user avatar
2 votes
2 answers
3k views

How to catch OptimisticLockException in JPA

I've read out a couple of questions here regarding the OptimisticLockException with JPA, used in an stateless session bean. It is thrown, but not where I expect it obviously. Here is the code where I ...
Aleksandar Stojadinovic's user avatar
5 votes
1 answer
918 views

Table indexes/pk for Optimistic Locking in JPA

What is the best practice for defining table indexes for entities supporting optimistic locking? For sure, entity id has to be part of some index in DB to enable fast lookups by id. What about ...
Andriy Kharchuk's user avatar
10 votes
2 answers
17k views

How to code optimistic and pessimistic locking from java code

I know what optimistic and pessimistic locking is, but when you write a java code how do you do it? Suppose I am using Oracle with Java, do I have any methods in JDBC that will help me do that? How ...
user2434's user avatar
  • 6,409
21 votes
2 answers
9k views

How do I avoid a race condition in my Rails app?

I have a really simple Rails application that allows users to register their attendance on a set of courses. The ActiveRecord models are as follows: class Course < ActiveRecord::Base has_many :...
Cathal's user avatar
  • 243
1051 votes
14 answers
706k views

Optimistic vs. Pessimistic locking

I understand the differences between optimistic and pessimistic locking. Now, could someone explain to me when I would use either one in general? And does the answer to this question change depending ...
Jason Baker's user avatar