You have the choice between optimistic and pessimistic locking. Oracle recommends using optimistic locking. For more information, see Descriptors and Locking.
By default, the EclipseLink persistence provider assumes that the application is responsible for data consistency.
Use the @Version
annotation to enable JPA-managed optimistic locking by specifying the version field or property of an entity class that serves as its optimistic lock value (recommended).
When choosing a version field or property, ensure that the following is true:
there is only one version field or property per entity
you choose a property or field persisted to the primary table (see "Table Annotation" in the JPA Specification)
your application does not modify the version property or field
Note: The field or property type must either be a numeric type (such as |
The @Version
annotation does not have attributes.
For more information, see the following:
"Optimistic Locking and Concurrency" in the JPA Specification http://jcp.org/en/jsr/detail?id=317
"Version Annotation" in the JPA Specification http://jcp.org/en/jsr/detail?id=317
EclipseLink JPA extensions for optimistic locking described in Java Persistence API (JPA) Extensions Reference for EclipseLink
For more information on the EclipseLink artifacts configured by JPA metadata, see Descriptors and Locking.