blob: 12d674e3bebb0696b06a0526271f1b59ae407beb [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>2.&nbsp; Integrating with the Transaction Manager</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA User's Guide"><link rel="up" href="ref_guide_deploy.html" title="Chapter&nbsp;8.&nbsp; Deployment"><link rel="prev" href="ref_guide_deploy.html" title="Chapter&nbsp;8.&nbsp; Deployment"><link rel="next" href="ref_guide_enterprise_xa.html" title="3.&nbsp; XA Transactions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">2.&nbsp;
Integrating with the Transaction Manager
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_deploy.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;8.&nbsp;
Deployment
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="ref_guide_enterprise_xa.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="ref_guide_enterprise_trans"></a>2.&nbsp;
Integrating with the Transaction Manager
</h2></div></div></div><a class="indexterm" name="d0e26781"></a><a class="indexterm" name="d0e26786"></a><a class="indexterm" name="d0e26791"></a><a class="indexterm" name="d0e26796"></a><p>
OpenJPA <code class="classname">EntityManager</code>s have the ability to automatically
synchronize their transactions with an external transaction manager. Whether
or not <code class="classname">EntityManager</code>s from a given <code class="classname">
EntityManagerFactory</code> exhibit this behavior by default depends on
the transaction type you set for the factory's persistence unit in
your <code class="filename">persistence.xml</code> file. OpenJPA uses the given
transaction type internally to set the
<a href="ref_guide_conf_openjpa.html#openjpa.TransactionMode" title="5.58.&nbsp; openjpa.TransactionMode"><code class="literal">openjpa.TransactionMode
</code></a> configuration property. This property accepts the following
modes:
</p><div class="itemizedlist"><ul type="disc"><li><p>
<code class="literal">local</code>: Perform transaction operations locally.
</p></li><li><p>
<code class="literal">managed</code>: Integrate with the application server's managed
global transactions.
</p></li></ul></div><p>
You can override the global transaction mode setting when you obtain an
<code class="classname">EntityManager</code> using the
<a xmlns:xlink="http://www.w3.org/1999/xlink" href="http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManagerFactory.html" target="_top">
<code class="classname">EntityManagerFactory</code></a>'s
<code class="methodname">createEntityManager(Map props)</code> method. Simply set the
<code class="literal">openjpa.TransactionMode</code> key of the given <code class="classname">Map
</code> to the desired value.
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
You can also override the <code class="literal">openjpa.ConnectionUserName</code>,
<code class="literal">openjpa.ConnectionPassword</code>, and <code class="literal">
openjpa.ConnectionRetainMode</code> settings using the given <code class="classname">
Map</code>.
</p></div><p>
<a class="indexterm" name="d0e26866"></a>
In order to use global transactions, OpenJPA must be able to access the
application server's <code class="classname">
javax.transaction.TransactionManager</code>. 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 <a href="ref_guide_conf_openjpa.html#openjpa.ManagedRuntime" title="5.39.&nbsp; openjpa.ManagedRuntime"><code class="literal">
openjpa.ManagedRuntime</code></a> configuration property. This
property describes an
<a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/ee/ManagedRuntime.html" target="_top"><code class="classname">
org.apache.openjpa.ee.ManagedRuntime</code></a> implementation to use
for transaction manager discovery. You can specify your own implementation,
or use one of the built-ins:
</p><div class="itemizedlist"><ul type="disc"><li><p>
<code class="literal">auto</code>: This is the default. It is an alias for the
<a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/ee/AutomaticManagedRuntime.html" target="_top">
<code class="classname">org.apache.openjpa.ee.AutomaticManagedRuntime</code></a>
class. This managed runtime is able to automatically integrate with several
common application servers.
</p></li><li><p>
<code class="literal">invocation</code>: An alias for the
<a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/ee/InvocationManagedRuntime.html" target="_top">
<code class="classname">org.apache.openjpa.ee.InvocationManagedRuntime</code></a>
class. You can configure this runtime to invoke any static
method in order to obtain the appserver's transaction manager.
</p></li><li><p>
<code class="literal">jndi</code>: An alias for the
<a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/ee/JNDIManagedRuntime.html" target="_top">
<code class="classname">org.apache.openjpa.ee.JNDIManagedRuntime</code></a>
class. You can configure this runtime to look up the transaction manager at
any JNDI location.
</p></li></ul></div><p>
See the Javadoc for of each class for details on the bean properties
you can pass to these plugins in your configuration string.
</p><div class="example"><a name="ref_guide_enterprise_transex"></a><p class="title"><b>Example&nbsp;8.1.&nbsp;Configuring Transaction Manager Integration</b></p><div class="example-contents"><pre class="programlisting">
&lt;property name="openjpa.TransactionMode" value="managed"/&gt;
&lt;property name="openjpa.ManagedRuntime" value="jndi(TransactionManagerName=java:/TransactionManager)"/&gt;
</pre></div></div><br class="example-break"></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ref_guide_deploy.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="ref_guide_deploy.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="ref_guide_enterprise_xa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;8.&nbsp;
Deployment
&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;3.&nbsp;
XA Transactions
</td></tr></table></div></body></html>