openjpa-dev mailing list archives

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

  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."


View this message in context:
Sent from the OpenJPA Developers mailing list archive at

View raw message