When coordinating updates from multiple database sessions, optimistic locking is a strategy that assumes all updates can complete without conflict. It does not hold locks on any records while the user is editing, but checks to see if any other edits have occurred when the user tries to commit the changes. If two sessions try to edit the same data, the second one to commit will be rejected and have to redo the change. Also see pessimistic locking.
Questions tagged [optimistic-locking]
422 questions
0
votes
1 answer
How to handle optimistic locking in case of updated_all?
I am trying to implement the Optimistic Locking for Race Condition. For that, I added an extra column lock_version in the Product: Model through migration.
Product: Model's new field:
# lock_version :integer(4) …

Neelabh Singh
- 2,600
- 12
- 51
- 88
0
votes
1 answer
Concurrency issues with Symfony and Doctrine
Good morning,
I have an issue when selecting the next record with Doctrine when there is concurrency. I have installed supervisord inside a docker container that starts multiple processes on the same "dispatch" command. The dispatch commands…

Mike
- 35
- 7
0
votes
2 answers
Handle Concurrency Java level vs database/JPA level
Scenario: In any kind of online Reservation application there is possiblty that people may acesses the application at the same time.
Because of this there could be a concurrency issues in that perticular application.
Problem:
In this case, if one…

Narayan Yerrabachu
- 1,714
- 1
- 19
- 31
0
votes
3 answers
simple optimistic lock question in jpa/spring/hibernate
I am trying to implement a basic optimistic lock mechanism with a retry interceptor.
So the thing is there is a object Quiz with a property responsesCount. In case that there is a optimistic Lock exception thrown during an update of the quiz, the…

Qfeast Quizzes
- 145
- 2
- 12
0
votes
0 answers
JPA 2.1 Timestamp type field for versioning and optimistic locking always throwing OptimisticLockException
Environment: JPA 2.1, EclipseLink 2.6.3, SQL Server 2016
I want to use a field of type Timestamp for versioning and optimistic. I do not have option to use numeric column for versioning. My understanding is I just need to annotate the field with…

Rakesh Prajapati
- 1,078
- 8
- 17
0
votes
1 answer
How to implement spring boot pessimistic lock and which approach is better optimistic lock or pessimistic lock?
Setup version on entity class
@Column(name = "VERSION")
@Version
private int version;
}
entityManager.find(getActiveUsers.class, 1, LockModeType.OPTIMISTIC);

Rupesh Kumar
- 15
- 3
0
votes
1 answer
Version property of Parent isn't incrementing if I update child
I'm using JPA 2 with Hibernate 3.x. I have two Entity objects Foo and Bar and the relation is like this -
@Entity
public class Foo{
@Id
private long id;
@OneToOne(cascade = CascadeType.ALL )
@JoinColumn(name = "bar")
private…

Premraj
- 7,802
- 8
- 45
- 66
0
votes
1 answer
How to write optimistic locking test cases in Rails
I need to test if my implementation of optimistic locking is correct or not. But I don't know how to test my functionalities. Here is the update action I wrote:
def update
begin
@update_operator = Operator.find(params[:id])
…

Darren
- 170
- 4
- 18
0
votes
1 answer
Getting org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null"
I am getting below exception while doing EntityManager.find(). We are using DB2 database and WAS 8.0 server for our application. Any help greatly appreciated.
Caused by: …

Kanhu Charan Sahu
- 157
- 1
- 11
0
votes
1 answer
hibernate optimistic lock: another thread update in between 2 updates in current thread
the timeline looks like this:
User(browser) ---------------------------> update TARGET 2----------------->
Thread ------> update TARGET 1 ---------> long_operation -----> update TARGET 3
I kick off a thread to execute an long_operation, and…

user2628641
- 2,035
- 4
- 29
- 45
0
votes
1 answer
Optimistic Lock Mechanism in Event Sourcing "UNDO" flow
I have been asking a lot of questions on event sourcing so apologies on that but I would like to nail this right from the get go.
SETUP
| p_key | invoice_id | EmployeeId | Event type | Version | Data…

Praveen
- 557
- 1
- 5
- 20
0
votes
1 answer
REST resource versioning
Everywhere you look, you see people recommending the use of the etag header in conjunction with if-match to do resource versioning in a REST API.
From reading the RFCs though, this is actually wrong.
Etags are particular to the representation,…

Graham
- 4,095
- 4
- 29
- 37
0
votes
1 answer
Spring transaction not rolled back on Hibernate StaleObjectStateException
I have a scenario as below
methodA(){
try{
objB.methodB();
}
catch(Exception ex){
log(exception caught);
}
@Transactional(value = "txManager", propagation = Propagation.REQUIRES_NEW,rollbackFor={Exception.class,…

varkashy
- 374
- 4
- 18
0
votes
0 answers
How can i manage optimistic lock from database and application
A Parent entity object that have some child and it's child maybe change the parent object status , for preventing from concurrency problem there is a nice solution that the name Is : Optimistic Lock
and this nice article from Vlad Mihalcea blog…

Mohammad Mirzaeyan
- 845
- 3
- 11
- 30
0
votes
1 answer
How to manage annotation based Hibernate versioning for time stamp column in which value generated by DB
We can generate version column's value by using below tag in our hbm file:

shashikant maheshwari
- 446
- 1
- 5
- 7