There is an entity:
@Entity
class A {
...
@Version
int version;
}
A
instances update implemented in optimistic manner:
@Transactional(rollbackFor = {StaleStateException.class})
@Retryable(value = {StaleStateException.class})
public void updateA() {
A a = findA();
B b = new B();
// Update "a" somehow
a.update();
// "b" is saved on each retry!
save(b);
}
As stated in comments, seems that transaction is not rollbacked when StaleStateException
occurs, so B
instance is saved on each retry.
Is it possible to rollback transaction on retry?
The desired behaviour is that b
is saved only on successfull a
update.