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
Post a Comment