title: How to handle OptimisticLockException in JPA/hibernate in jboss?
body: <p>I am using JPA to handle entities in JBOSS.One Entity will be updated by several threads in various transactions.I have @Version attribute added in my entity and also before updating entity i am obtaining OptimisticLock.I cant handle the exceptions and retry if transaction fails.  </p>
  
  <p><strong>The Entity is</strong>  </p>
  
  <pre><code>@Entity  
  public class DataEntity   
  {  
      @Id  
      int id;  
      long count;  
      @Version  
      int versionAttribute;  
       ....  
       ....  
  </code></pre>
  
  <p><strong>The Code which updates the entities is</strong> </p>
  
  <pre><code>@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  public void updateEntity()  
  {  
       DataEntity d=entityManager.find(DataEntity.class,0,LockModeType.OPTIMISTIC);
       d.setCount(d.getCount()+1);  
  }  
  </code></pre>
  
  <p>As you  can see the method updateEntity() uses TransactionAttributeType.REQUIRES_NEW to have a new transaction.  Here transactions are container managed.So help me on doing a retry when an OptimisticLockingException is Thrown. </p>
  
  <p>Where to handle exception? /Where to write the retry Logic?</p>