Skip Headers

Oracle TopLink Developer's Guide 10g Release 3 (10.1.3) B13593-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Optimistic Lock Exceptions (5001 – 5008)

`OptimisticLockException` is a run-time exception that is raised when the row on the database that matches the desired object is missing or when the value on the database does not match the registered number. It is used in conjunction with the optimistic locking feature. This applies only on an update or delete operation, as shown in Example 13-5.

For more information about optimistic locking, see the section on Optimistic Locking in a Stateless Environment in Chapter 2, "Understanding TopLink Application Development". These exceptions should be handled in a try-catch block.

Format

    EXCEPTION [TOPLINK – error code]: Exception Name
    EXCEPTION DESCRIPTION: Message

Example 13-5 Optimistic Lock Exception

    EXCEPTION [TOPLINK – 5003]: oracle.toplink.exceptions.OptimisticLockException
    EXCEPTION DESCRIPTION: The object, object.toString() cannot be deleted because it has changed or been deleted since it was last read.

5001: NO_VERSION_NUMBER_WHEN_DELETING
  Cause: An attempt was made to delete the object `object`, but it has no version number in the identity map. This object either was never read or has already been deleted.
  Action: Use SQL logging to determine the reason for the exception. The last delete operation shows the object being deleted when the exception was raised.

5003: OBJECT_CHANGED_SINCE_LAST_READ_WHEN_DELETING
  Cause: The object state has changed in the database. The object `object` cannot be deleted because it has changed or been deleted since it was last read. This usually means that the row in the table was changed by some other application.
  Action: Refresh the object, which updates it with the new data from the database.

5004: NO_VERSION_NUMBER_WHEN_UPDATING
  Cause: An attempt has been made to update the object `object` but it has no version number in the identity map. It may not have been read before being updated, or it has been deleted.
  Action: Use SQL logging to determine the reason for the exception. The last update operation shows the object being updated when the exception was raised.

5006: OBJECT_CHANGED_SINCE_LAST_READ_WHEN_UPDATING
  Cause: The object state has changed in the database. The object `object` cannot be updated because it has changed or been deleted since it was last read. This usually means that the row in the table was changed by some other application.
  Action: Refresh the object, which updates it with the new data from the database.

5007: MUST_HAVE_MAPPING_WHEN_IN_OBJECT
  Cause: The object `aClass` must have a nonread-only mapping corresponding to the version lock field. The mapping, which is needed when the lock value is stored in the domain object rather than in a cache, was not defined for the locking field.
  Action: Define a mapping for the field.

5008: NEED_TO_MAP_JAVA_SQL_TIMESTAMP
  Cause: A write lock value that is stored in a domain object is not an instance of`java.sql.Timestamp`.
  Action: Change the value of the attribute to be an instance of `java.sql.Timestamp`.