Annotation Type OptimisticLocking
-
@Target(TYPE) @Retention(RUNTIME) public @interface OptimisticLocking
Specifies how optimistic lock checking works for the annotated entity.Optimistic lock checking may detect that an optimistic lock has failed, and that the transaction should be aborted, by comparing either:
- the version or timestamp,
- the dirty fields of the entity instance, or
- all fields of the entity.
An optimistic lock is usually checked by including a restriction in a SQL
update
ordelete
statement. If the database reports that zero rows were updated, it is inferred that another transaction has already updated or deleted the row, and the failure of the optimistic lock is reported via anOptimisticLockException
.In an inheritance hierarchy, this annotation may only be applied to the root entity, since the optimistic lock checking strategy is inherited by entity subclasses.
To exclude a particular attribute from optimistic locking, annotate the attribute
@OptimisticLock(excluded=true)
. Then:- changes to that attribute will never trigger a version increment, and
- the attribute will not be included in the list of fields checked fields
when
OptimisticLockType.ALL
orOptimisticLockType.DIRTY
is used.
- See Also:
LockMode
,LockModeType
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description OptimisticLockType
type
The optimistic lock checking strategy.
-
-
-
Element Detail
-
type
OptimisticLockType type
The optimistic lock checking strategy.- Default:
- org.hibernate.annotations.OptimisticLockType.VERSION
-
-