Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Optimistic concurrency with hibernate: version not increasing

Pascal Zwick
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am developing a web application using spring boot and spring data jpa (hibernate). I implemented optimistic concurrency using the @Version annotation. My domain object has the field "version" (int) and that annotation. Also i added the version to my database. If i create my entity using my frontend it writes the entity successfully to the database with the version 0. Then i am editing my entity using my frontend and submitting the changes. The data are submitted successfully to the database again and the version is 1. Looks good...but now...if i change my entity again (like before) i get an StaleObjectstateException and no data are submitted to the database. Do you have any idea? Of course, if two users are changing the data the StaleObjectstateException is thrown. Thats exactly what i want, but here i am working only with one user and i expect, that one user can always change the data and the version changes.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!