java - how to raise OptimisticLockException -
unable catch optimistic lock exception.
one way raise optimisticlockexception using em.flush()
try{ //some enitity em.flush() } catch(optimisticlockexception ole){}
but dont think best solution beacuse in full database flush.
another work around catching ejbexception
, find rollbackexception
in ..
try{ // code } catch (ejbexception ex) { if (ex.getcausedbyexception().getcause().tostring(). indexof("javax.transaction.rollbackexception")!= -1){ // work } } }
please have other idea or tell me way better.
i think first way reasonable way if want catch optimisticlockexception , refresh data or retry operation. second way, if current transaction not active, there no rollbackexception thrown.
Comments
Post a Comment