+ 10

Qus:- Explain the different ways Hibernate manages concurrency?

19th May 2019, 10:17 AM
Deepika Mourya
Deepika Mourya - avatar
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
19th May 2019, 10:36 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 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
19th May 2019, 10:26 AM
Muhammad Rashid
Muhammad Rashid - avatar