Annotation Interface Version


@Target({METHOD,FIELD}) @Retention(RUNTIME) public @interface Version
Declares the version field or property of an entity class, which is used to detect optimistic lock failures, ensuring the integrity of optimistic transactions. The version field or property holds a version number or timestamp identifying the revision of the entity data held by an entity class instance.

An optimistic lock failure occurs when verification of the version or timestamp fails during an attempt to update the entity, that is, if the version or timestamp held in the database changes between reading the state of an entity instance and attempting to update or delete the state of the instance.

The version attribute must be of one of the following basic types: int, Integer, short, Short, long, Long, java.sql.Timestamp, Instant, LocalDateTime.

This field declares a version number:

This field declares a revision timestamp:

An entity class should have at most one Version field or property. The version field or property should be declared by the root entity class in an entity class hierarchy, or by one of its mapped superclasses.

The Version field or property should be mapped to the primary table of the entity.

Since:
1.0
See Also: