Marco Belladelli (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=637b480...
) *commented* on HHH-16111 (
https://hibernate.atlassian.net/browse/HHH-16111?atlOrigin=eyJpIjoiOWU5ZW...
)
Re: Field annotated with @Version does not increase when entity is updated using merge (
https://hibernate.atlassian.net/browse/HHH-16111?atlOrigin=eyJpIjoiOWU5ZW...
)
Hello Vijayasaradhi Danda (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) , 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 (
https://jakarta.ee/specifications/persistence/3.1/jakarta-persistence-spe...
).
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!
(
https://hibernate.atlassian.net/browse/HHH-16111#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16111#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100214- sha1:6115380 )