I have already read the hibernate docs about concurrency and I think, I have understood the available locking methods, but I am not sure how I should implement the following scenario.
Two clients F (fast) and S (slow) access the database and can modify the same objects.
Now, one additional requirement: It is critical to the application that client F performs as fast as possible.
How would you solve the problem?
My problem with optimistic locking: Assume that F tries to update its changes but couldn't do this successfully, because S already updated its data. An exception (StaleObjectStateException) will be thrown from hibernate. I will catch this exception and merge the changes and try exactly the same transaction again, right? Then I don't like the case where F retries its transactions until it was successfull and so F could theoretically block a long time. Should I ignore this and hope that this condition is rare in practise? Or can I give my clients something like a database-locking-priority?
Other users can live with this problems:
StaleObjectStateException (Optimistic Locking) ... we get 3 exceptions per 10000 calls.