I have 2 objects: Parentand Childin a one-to-many relationship. Parenthas a version, that is, has a @Version field. My goal is to synchronize changes both with objects Parentand Childin the version Parent.
eg. one thread updates Parent, and the other updates one of them Childs, this should throw an OptimisticLockException.
Is it possible?
I tried adding @PreUpdate to Child, which would increase its version Parent, but that did not help, because Hibernate seems to execute listeners only after it checks the versions so that the transaction successfully completes in any case.
If possible, how can this be implemented?
source
share