openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <ppod...@apache.org>
Subject Re: QUERY: detach/merge behavior
Date Wed, 23 Jul 2008 19:25:44 GMT

Hi,
  Following excerpt from Chapter 11 [1] of the manual may be relevant in
this context: 

"When detaching an instance that has been modified in the current
transaction (and thus made dirty), the current transaction is flushed. This
means that when subsequently re-attaching the detached instances, OpenJPA
assumes that the transaction from which they were originally detached was
committed; if it has been rolled back, then the re-attachment process will
throw an optimistic concurrency exception.

You can stop OpenJPA from assuming the transaction will commit in the
following ways :

    * Invoke EntityTransaction.setRollbackOnly prior to detaching your
objects. Setting the RollbackOnly flag prevents OpenJPA from flushing when
detaching dirty objects; instead OpenJPA just runs its pre-flush actions
(see the OpenJPAEntityManager.preFlush Javadoc for details).

      This allows you to use the same instances in multiple
attach/modify/detach/rollback cycles.

    * Make your modifications outside of a transaction (with
NontransactionalWrite enabled) before detaching.

    * Set flushBeforeDetach to false (see Compatibility.setFlushBeforeDetach
Javadoc ). This option is similar to the first option, but does not affect
the current transaction."

[1]
http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_detach

-- 
View this message in context: http://n2.nabble.com/QUERY%3A-detach-merge-behavior-tp578652p579098.html
Sent from the OpenJPA Developers mailing list archive at Nabble.com.


Mime
View raw message