Hello Vijayasaradhi Danda, thanks for reporting the issue and providing a reproducer! Looks like in Hibernate 5 you were using the Session#update method, and migrated to using merge with H6. The parent entity in your example has a @ManyToOne(mappedBy=...) association, making it the non-owning side of a bidirectional association. In this case, the JPA spec indicates that the Version attribute used for Optimistic Locking should not be increased. You can read more about version attributes here. When using Session#update your case worked only because without the SelectBeforeUpdate mapping on your entity, Hibernate’s update method forces an update for the detached parent entity, regardless of its state, thus triggering the Verison increase you expected. If you want the Version attribute to be increased, you should remove the mappedBy from the parent side of the association and add the @JoinColumn there, making it the owning side of the relationship and triggering Optimistic Locking every time you make changes to the child entities collection. Let me know if you need additional help with your issue! |