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