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
0 answers
Optimistic concurrency with EF Core 2 and PostgreSQL
With EF Core 1 I used uint property for concurrency checks, cofigured this way:
entityBuilder.Property(e => e.ConcurrencyStamp)
.ForNpgsqlHasColumnName("xmin")
.ForNpgsqlHasColumnType("xid")
.ValueGeneratedOnAddOrUpdate()
…

Fanda
- 3,760
- 5
- 37
- 56
0
votes
1 answer
Getting an optimistic lock without updating data in entity
Following is the code snippet I am using to get an optimistic lock.
setting = this.entityManager.find(Setting.class, id, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
setting.setUpdateTimestamp(new Date()); // I want to make sure that this setting is…

Vrishank
- 302
- 4
- 22
0
votes
1 answer
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 another transaction happens to committed after it…

user2015063
- 99
- 1
- 7
0
votes
0 answers
Optimistic Locking for OneToOne Relationships
I have person page. In this page I have person, person_group, person_detail classes. I show person's information in this page with 3 classes. I want to add optimistic lock. Person is my main class. Person has one-to-one relationship with…

Yusuf önder
- 1
- 1
0
votes
1 answer
Error Persisting a list of entities using java parallel streams
I wanted to persist a list of entities using JPA. My first approach was as follows:
ListentityList=myService.getMyEntities();`
\\some other…

Lakshi
- 490
- 4
- 10
0
votes
1 answer
javax.persistence.version causes the Id of an entity to remain null in the transaction
I have two entities with typical primary foreign key relationship. id in EntityA is has foreign key relationship in EntityB. I am trying to persist entity A and entity B in same transaction.
Entity…

somename
- 978
- 11
- 30
0
votes
0 answers
Does OptimisticLockException occurs before hitting physical DB layer?
Say that we are using Hibernate as a JPA implementation and as you all know it has a cache mechanism called first-level-cache.
Is OptimisticLockException is thrown from this cache layer or does it really hits the DB and sees that the version of…

jit
- 452
- 1
- 7
- 26
0
votes
1 answer
Yii: disable optimistic locking
I have enabled the optimistic locking feature in my Yii aplication by accident. Now it is causing problems, and I want to disable it. Is there a painless way to do this (i.e. update my models and CRUD without having to create them again)?

Eutherpy
- 4,471
- 7
- 40
- 64
0
votes
2 answers
NHibernate shoots itself in the foot: Association ownership and versioning
Situation
Assume:
NHibernate 4
A parent/child relationship (one-to-many), uni-directional mapping from parent to child
Inverse(false), i.e. the parent is responsible for the association
Cascade.All from parent to child
Versioning (database column…

domin
- 1,192
- 1
- 7
- 28
0
votes
1 answer
Saving an object with eager loaded parameters and OptimisticLockException
I have an object called Classroom:
@Entity
public class Classroom {
@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST })
@JoinColumn(name = "girl", referencedColumnName = "id", nullable = true)
private…

Joetjah
- 6,292
- 8
- 55
- 90
0
votes
1 answer
JPA/EclipseLink handling of @Version
In an application using EclipseLink 2.5 and container-managed transactions that needs to merge detached entities from time to time, each entity contains a field with the @Version annotation. Some implementation of optimistic locking is necessary,…

Lord Zuthulu
- 143
- 1
- 7
0
votes
1 answer
How to know whether persistent entity was updated or not? Spring Transaction Management
I am trying to implement optimistic locking using JPA. I read that adding one additional field, version with @Version annotation can used to apply implicit optimistic locking. After implementing, I will be able to prevent lost updates in case of…

Md Zahid Raza
- 941
- 1
- 11
- 28
0
votes
0 answers
Behavior of Optimistic JPA locking when record is locked by another application at DB level
We have an Informix DB table used by multiple tech stacks like ESQL/C, Java (JPA), db batch updates. The below is the production issue that keeps bugging us (not often, though).
Caused by: org.hibernate.exception.GenericJDBCException: could not…

krisp
- 73
- 1
- 7
0
votes
1 answer
How to handle optimistic concurrency for REST resources?
I'm using a RESTful framework (Flask-Restless 0.17.0 with Flask-SQLAlchemy) as a backend. And AngularJS as a frontend.
I know one can handle concurrency using for example a version column (or a timestamp or a checksum of the data) for a single…

Wieger
- 663
- 1
- 9
- 24
0
votes
1 answer
Optimistic Locking Unit Test Minitest
The Problem...
Trying to create a test that demonstrates that optimistic locking prevents the save BUT the action of saving actually raises the ActiveRecord::StaleObjectError: Attempted to update a stale object: Invoice error, blowing up the test.…

CheeseFry
- 1,299
- 1
- 21
- 38