How to know whether persistent entity was updated or not? Spring Transaction Management
I am trying to implement optimistic locking using JPA. I read that adding one additional field, version with @Version annotation can used to apply implicit optimistic locking. After implementing, I will be able to prevent lost updates in case of multiple users trying to update the same entity.If any update is made and if version field do not match with the version field of entity, meaning entity was updated meanwhile by other user, then no row is updated, thereby preventing lost update.
I am using Spring Transaction management support where for updating entity, all I have to is update the Entity fields and database update is taken care by Spring transaction manager, meaning I need not call update query explicitly.
My Question is that, How would I be able to know if update made for a particular user was successful?Автор: Md Zahid Raza Источник Размещён: 08.11.2019 11:04
OptimisticLockException will be thrown if an operation was unsuccessful - if other transaction has modified entity before. Related threads for more details:
- JPA: pattern for handling OptimisticLockException
- How JPA knows when it have to throw OptimisticLockException?