2.4.1.4. Version Field
The version field in our Magazine class may seem out of place.
JPA uses a version field in your entities to detect concurrent modifications to the same datastore record.
When the JPA runtime detects an attempt to concurrently modify the same record, it throws an exception to the transaction attempting to commit last.
This prevents overwriting the previous commit with stale data.
A version field is not required, but without one concurrent threads or processes might succeed in making conflicting changes to the same record at the same time. This is unacceptable to most applications. Version shows you how to designate a version field in JPA metadata.
The version field must be an integral type (int, Long, etc), a java.sql.Timestamp, a java.time.LocalDateTime or a java.time.Instant.
You should consider version fields immutable.
Changing the field value has undefined results.
|
|
OpenJPA fully supports version fields, but does not require them within the actual entity for concurrency detection. OpenJPA can maintain surrogate version values or use state comparisons to detect concurrent modifications. See Additional JPA Mappings in the Reference Guide. |