JPA @Version behaviour

后端 未结 1 533
长发绾君心
长发绾君心 2021-01-04 18:49

im using JPA2 with Hibernate 3.6.x

I have made a simple testing on the @Version.

Let\'s say we have 2 entities,

  1. Entity Team has a List of Play
相关标签:
1条回答
  • 2021-01-04 19:41

    It looks like a bug in Hibernate.

    JPA Specification says:

    All non-relationship fields and properties and all relationships owned by the entity are included in version checks

    However, Hibernate also increments version after change of non-owned relationship properties (whereas, for example, EclipseLink doesn't do it). This behaviour can be disabled by setting @OptimisticLock(exclude = true) on the property.

    Note that it's only applicable to changes of relationship property itself, not to changes in the state of referenced objects, so that version of parent wouldn't be changes due to changes in collection of grandchildren.

    0 讨论(0)
提交回复
热议问题