Skip to content

Conversation

@jonasPoehler
Copy link
Contributor

This PR makes sure, that a generated property like a @Version-property gets reset when an OptimisticLockException is thrown. This is a particular problem in the following case:

  1. A loads bean with version 1
  2. B loads bean with version 1
  3. A updates bean with version 1 (gets incremented to 2)
  4. B tries to update bean with version 1, but gets OptimisticLockException (version on bean in memory stays incremented, now 2 -- wrong)
  5. B now can save again, since the version matches now, and A's changes are overwritten.

With this change the version would be rolled back in step 4, making sure, that simply saving a second time doesn't change the behaviour.

@rbygrave rbygrave added this to the 12.11.5 milestone Sep 15, 2021
@rbygrave
Copy link
Member

Nice one, I like it !!

@rbygrave rbygrave merged commit 41bbfb0 into ebean-orm:master Sep 15, 2021
@jonasPoehler jonasPoehler deleted the pr/bugfix/optimistic_lock_undo_generated_properties branch September 16, 2021 11:33
rPraml added a commit to FOCONIS/ebean that referenced this pull request Jul 2, 2025
With ebean-orm#2372 we introduced a rollback mechanism when an optimisticLock
happend, so that you can correct the issue and retry. This PR also
handles the situation for other persistence exceptions like DuplicateKey
rPraml added a commit to FOCONIS/ebean that referenced this pull request Jul 2, 2025
…eExceptions

With ebean-orm#2372 we introduced a rollback mechanism when an optimisticLock
happend, so that you can correct the issue and retry. This PR also
handles the situation for other persistence exceptions like DuplicateKey

fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants