java - Will JPA EntityManager's merge method lead to OptimisticLockException? -


let's merge detached entity. when do

t mergedentity = entitymanager.merge(detachedentity); 

the entitymanager load entity (with same identifier detachedentity) database , copy data detachedentity new loaded entity. when later transaction ends, entity saved database.

however, in concurrent scenario, entity in database can updated other transactions between entity firstly loaded in transaction , flushed @ end of transaction. in case, know whether optimisticlockexception thrown? if so, why merge api doesn't specify optimisticlockexception in java doc? http://docs.oracle.com/javaee/6/api/javax/persistence/entitymanager.html#merge(t)

thanks

because merge() method not throw exception. exception thrown when state of entity, in memory, flushed database. doesn't happen when merge() called, when flush() called, either explicitely, or before commit, or before query executed.


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -