I have a question about StaleStateException and optimistic locking that I can't seem to find answered in the documentation. I want to know if there is a way to declare a class with a version attribute, so that it will throw a StaleStateException if the version check doesn't match, but retain the ability to ignore the version check when appropriate and let the update go through regardless of whether it trashes some other thread's changes to the object.
The reason for this is that I am migrating a legacy application, and the existing behavior is to detect the update collision, warn the user, and then ask them if they really want to go ahead with the update even though someone else has modified the object. If the user chooses to trash the other person's changes, so be it -- we do the update.
I would like to use the optimistic locking that hibernate provides to detect and prevent lost updates, but I need to be able to force an update when I have to, even if my object is stale.
Is there a provided technique for this, or am I stuck implementing the optimistic locking in the application layer?
|