Using Field Locking Policies
The following locking policies, included in TopLink, do not require any additional fields:
- AllFieldsLockingPolicy
- ChangedFieldsLockingPolicy
- SelectedFieldsLockingPolicy
All these policies compare the current values of certain mapped previous values. When using these policies, a UnitOfWork must be employed for updating the database. Each policy handles its field comparisons in specific way, as defined by the policy.
- Whenever an object using AllFieldsLockingPolicy is updated or deleted, all the fields in that table are compared in the where clause. If any value in that table has been changed since the object was read, the update or delete fails.
Note: This comparison is only on a per table basis. If an update is performed on an object that is mapped to multiple tables (multiple table inheritance), then only the changed table(s) appear in the where clause.
- Whenever an object using ChangedFieldsLockingPolicy is updated, only the modified fields are compared. This allows for multiple clients to modify different parts of the same row without failure. Using this policy, a delete compares only on the primary key.
- Whenever an object using SelectedFieldsLockingPolicy is updated or deleted, a list of selected fields is compared in the statement. Updating these fields must be done by the application manually or through an event.
Whenever any update fails because optimistic locking has been violated, an OptimisticLockException is thrown. This should be handled by the application when performing any database modification The application must refresh the object and reapply its changes.
Related Topics
About TopLink Descriptors
Using Version Locking Policies
Specifying Advanced Optimistic Locking Policies
Working with Optimistic Locking
Working with Descriptors
Copyright © 1997, 2004, Oracle.
All rights reserved.