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

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -