Skip Headers

# Optimistic Lock Exceptions (5001 – 5009)

Previous

Next

`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: Optimistic Lock Exception.

For more information about optimistic locking, see the section on Optimistic locking in a stateless environment in Understanding TopLink Application Development. These exceptions should be handled in a try-catch block.

Format

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

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: Attempt to delete the object `object` that does not have a 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` that does not have a 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 `object` does not have a non-read-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`.

5009: UNWRAPPING_OBJECT_DELETED_SINCE_LAST_READ
  Cause: Attempt to unwrapped an object of class `className` with primary key `key`–the object was deleted since it had been last read.
  Action: Ensure the existence of the object being upwrapped.