Use @OptimisticLocking to specify the type of optimistic locking EclipseLink should use when updating or deleting entities.
Annotation Elements
Table 2-45 describes this annotation's elements.
Table 2-45 @OptimisticLocking Annotation Elements
| Annotation Element | Description | Default |
|---|---|---|
|
|
(Optional) Specify where the optimistic locking policy should cascade lock. When changing private owned and delete orphan object, EclipseLink will update the version. Currently only supported with |
|
|
|
(Optional) Specify a list of columns that will be optimistically locked. This element is required when |
|
|
|
(Optional) The type of optimistic locking policy to use:
|
|
Usage
You can specify @OptimisticLocking on an Entity or MappedSuperclass.
Examples
Example 2-83 shows how to use the @OptimisticLocking annotation for all columns
Example 2-83 Using @OptimisticLocking Annotation
@Table(name = "EMPLOYEES")
@OptimisticLocking(type=OptimisticLockingType.ALL_COLUMNS)
public class Employee implements Serializable {
...
}
Example 2-83 shows how to use the <optimistic-locking> element in the eclipselink-orm.xml file for a single column.
Example 2-84 Using <optimistic-locking> XML
<entity name="Employee" class="my.Employee" access="PROPERTY" change-tracking="DEFERRED">
...
<optimistic-locking type="SELECTED_COLUMNS" cascade="false">
<selected-column name="id"/>
<selected-column name="firstName"/>
</optimistic-locking>
...
</entity>
See Also
For more information, see:
"Scaling EclipseLink Applications in Clusters" in Solutions Guide for EclispeLink