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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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