EntityManagers have the ability to automatically
synchronize their transactions with an external transaction manager. Whether
EntityManagers from a given
EntityManagerFactory exhibit this behavior by default depends on
the transaction type you set for the factory's persistence unit in
persistence.xml file. OpenJPA uses the given
transaction type internally to set the
configuration property. This property accepts the following
local: Perform transaction operations locally.
managed: Integrate with the application server's managed
You can override the global transaction mode setting when you obtain an
EntityManager using the
createEntityManager(Map props) method. Simply set the
openjpa.TransactionMode key of the given
to the desired value.
You can also override the
openjpa.ConnectionRetainMode settings using the given
In order to use global transactions, OpenJPA must be able to access the
javax.transaction.TransactionManager. OpenJPA can automatically
discover the transaction manager for most major application servers.
Occasionally, however, you might have to point OpenJPA to the transaction
manager for an unrecognized or non-standard application server setup. This is
accomplished through the
openjpa.ManagedRuntime configuration property. This
property describes an
org.apache.openjpa.ee.ManagedRuntime implementation to use
for transaction manager discovery. You can specify your own implementation,
or use one of the built-ins:
auto: This is the default. It is an alias for the
class. This managed runtime is able to automatically integrate with several
common application servers.
invocation: An alias for the
class. You can configure this runtime to invoke any static
method in order to obtain the appserver's transaction manager.
jndi: An alias for the
class. You can configure this runtime to look up the transaction manager at
any JNDI location.
See the Javadoc for of each class for details on the bean properties you can pass to these plugins in your configuration string.
Example 8.1. Configuring Transaction Manager Integration
<property name="openjpa.TransactionMode" value="managed"/> <property name="openjpa.ManagedRuntime" value="jndi(TransactionManagerName=java:/TransactionManager)"/>