title: how to raise OptimisticLockException
body: <p>Unable to catch optimistic lock exception.</p>
  
  <p>one way to raise  OptimisticLockException is by using em.flush()</p>
  
  <pre><code>try{
     //some enitity
     em.flush()
    }
  catch(OptimisticLockException ole){}
  </code></pre>
  
  <p>but i dont think this is best solution beacuse in this full database is flush.</p>
  
  <p>another work around is by catching <code>EJBException</code> and find <code>RollBackException</code> in that ..</p>
  
  <pre><code>       try{
              // some code
          }
         catch (EJBException ex) {
  
            if (ex.getCausedByException().getCause().toString().
                indexOf("javax.transaction.RollbackException")!= -1){
                     // do work
                }     
            }
         }
  </code></pre>
  
  <p>Please help do you have any other idea or tell me which way is better.</p>