How to know whether persistent entity was updated or not? Spring Transaction Management

spring hibernate jpa spring-transactions optimistic-locking

100 просмотра

1 ответ

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

Ответы (1)

0 плюса

OptimisticLockException will be thrown if an operation was unsuccessful - if other transaction has modified entity before. Related threads for more details:

Автор: Justas Размещён: 20.08.2016 11:49
Вопросы из категории :