Questions tagged [optimistic-locking]

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.

422 questions
11
votes
3 answers

How to manually set the @Version fields with Hibernate 4?

Environment: I have that User entity : @Entity public class User implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer userId; …
Anthony O.
  • 22,041
  • 18
  • 107
  • 163
11
votes
2 answers

Is Optimistic-Locking absolutely safe?

when using optimistic-locking strategy, it can solve concurrency problem like below: | the first transaction started | | | | select a row | | …
Yugang Zhou
  • 7,123
  • 6
  • 32
  • 60
10
votes
2 answers

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 will I configure this thing? Any pointers will be…
user2434
  • 6,339
  • 18
  • 63
  • 87
10
votes
2 answers

How to do optimistic locking in hibernate

I am completely new to Hibernate and Spring and in my attempt to learn Spring, Hibernate, Maven etc I only know how to run a hello world example using all of the three. With my basic understanding I have been assigned a task for performing…
Anupam Gupta
  • 1,591
  • 8
  • 36
  • 60
10
votes
3 answers

Optimistic locking in a RESTful application

At work, we're developing a RESTful application where the data layer will be handled by Hibernate. But we're not sure how to handle updates on entities. We're planning to do the following: 1) client requests an entity by id 2) Hibernate loads the…
user2054927
  • 969
  • 1
  • 12
  • 30
9
votes
1 answer

How does one gracefully merge object graphs after NHibernate StaleObjectStateException?

We are trying to combine objects after a StaleObjectStateException has been thrown to save a merged copy. Here's our environmental situation: List item Multi-user system WPF Desktop application, SQL Server 2008 database NHibernate 3.1.0.4000,…
9
votes
1 answer

Spring Data: rollback transaction on retry

There is an entity: @Entity class A { ... @Version int version; } A instances update implemented in optimistic manner: @Transactional(rollbackFor = {StaleStateException.class}) @Retryable(value = {StaleStateException.class}) public…
Aliaxander
  • 2,547
  • 4
  • 20
  • 45
9
votes
6 answers

How to do concurrent modification testing for grails application

I'd like to run tests that simulate users modifying certain data at the same time for a grails application. Are there any plug-ins / tools / mechanisms I can use to do this efficiently? They don't have to be grails specific. It should be possible to…
9
votes
2 answers

ETags and collections

Many REST APIs provide the ability to search for resources. For example, resources of type A may be fetched using the following HTTP request: GET /A?prop1={value1}&prop2={value2} I'm using optimistic locking and therefore would like to return a…
manash
  • 6,985
  • 12
  • 65
  • 125
8
votes
1 answer

When to explicitly exclude Optimistic Locking (Hibernate)?

Under what circumstances would it be appropriate to explicitly exclude optimistic locking from a @OneToMany relationship via Hibernate? I have been reading a post on Hibernate which basically says any updates to child entities will cause an…
Ben Simmons
  • 1,858
  • 3
  • 21
  • 31
8
votes
2 answers

Why should I use Repeatable Read(or higher) isolation level if I need to read version the second time?

I've read Martin Fowler's book chapter Optimistic Offline Lock Author describes following example(if I understood it correctly): There are 2 entites: Order and Client. There are 2 transactions(business) involved: First transaction calculates…
8
votes
2 answers

Dirty (changed) attributes: since when are the values in the changeset strings (instead of objects)?

I'm using optimistic locking to prevent people overwriting each others changes in race conditions. Since I upgraded Rails from 5.1 to 5.2, my specs break, and I tracked it down to the fact that in the changes array, the changes that are related to a…
Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152
8
votes
1 answer

Implementing Optimistic lock using Hibernate and Spring

I am trying to implement Optimistic locking in-order to avoid lost update situation. In my application when two user fetch same record and the first user updates it with some changes. This change is not visible to the second user who view the same…
Leejoy
  • 1,356
  • 5
  • 23
  • 36
8
votes
1 answer

How do you implement a coarse-grained optimistic lock in REST?

I have implemented optimistic locking for my REST resources that have 1-to-1 mapping to database tables by passing back a version number which was in the GET back through to the PUT call. If the version number changed in the database between the…
BestPractices
  • 12,738
  • 29
  • 96
  • 140
7
votes
2 answers

Getting Stale object error. Optimistic Locking: How does it work?

I think I've eliminated everything, but I'm not sure I understand OL perfectly enough to be sure. In general, let's say you and I are on a team to keep a foo up to date. I'm in one room and decide to save time I'll update the foo myself. So I start…
MCB
  • 2,021
  • 1
  • 18
  • 32
1
2
3
28 29