title: Optimistic locking and full table lock
body: <p>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.<br>
  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.</p>
  
  <p>We are using hibernate on a JBoss 4.2 server, and the database could either be MySQL or SQL Server.</p>
  
  <p>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?</p>
  
  <p><strong>Edit:</strong><br>
  What we actually see is not an optimistic locking error, but a deadlock:</p>
  
  <blockquote>
    <p>SQLServerException: Transaction was deadlocked on lock resources with
    another process and has been chosen as the deadlock victim. Rerun the transaction.</p>
  </blockquote>
  
  <p>We deal with this in the code, but I was wondering if @Version could be of any help in this case.<br>
  At least in one of the cases this deadlock was caused by a table lock, where two clients were working with there own data.</p>