+ 10
Qus:- Explain the different ways Hibernate manages concurrency?
2 Respostas
+ 12
Question is copied as well as the answer.
Android Developer👨💻 if you copy answer from any source then please include that source link too
https://stackoverflow.com/questions/3616321/concurrent-updates-handling-in-hibernate/3618445
+ 3
Answer
Whether you're using Spring for transaction management or not doesn't really matter and isn't relevant when it comes to concurrency management, this is actually handled by Hibernate. Hibernate can use 2 strategies to handle concurrent updates: optimistic locking and pessimistic locking.
Optimistic
When using optimistic locking, you map a special attribute (a number, a timestamp) as a version (so you actually have a column for it). This version is read when you retrieve an entity and included in the where clause during an update and incremented by Hibernate.
To illustrate how this works, let's imagine you load a Person entity by id=1 and with a current version=1. After a save, Hibernate will perform something like this:
update PERSON set