We have a system where we once in a while get an optimistic locking exception. We have worked around this in the code, but now I am looking at JPA 2 and see that it has an annotation (@Version) for dealing with this.
The problem we have is that more than one transaction is working on a table, and with a full table lock this causes the optimistic locking exception even though changes are not made to the same records.
We are using hibernate on a JBoss 4.2 server, and the database could either be MySQL or SQL Server.
If we changed to using @Version instead, would this enforce row lock on both databases or can we still expect to see optimistic locking exception caused by full table lock?
Edit:
What we actually see is not an optimistic locking error, but a deadlock:
SQLServerException: Transaction was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
We deal with this in the code, but I was wondering if @Version could be of any help in this case.
At least in one of the cases this deadlock was caused by a table lock, where two clients were working with there own data.