| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>2. Integrating with the Transaction Manager</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><link rel="home" href="manual.html" title="Apache OpenJPA 3.0 User's Guide"><link rel="up" href="ref_guide_deploy.html" title="Chapter 8. Deployment"><link rel="prev" href="ref_guide_deploy.html" title="Chapter 8. Deployment"><link rel="next" href="ref_guide_enterprise_xa.html" title="3. 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. |
| Integrating with the Transaction Manager |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ref_guide_deploy.html">Prev</a> </td><th width="60%" align="center">Chapter 8. |
| Deployment |
| </th><td width="20%" align="right"> <a accesskey="n" href="ref_guide_enterprise_xa.html">Next</a></td></tr></table><hr></div><div class="section" id="ref_guide_enterprise_trans"><div class="titlepage"><div><div><h2 class="title" style="clear: both">2. |
| Integrating with the Transaction Manager |
| </h2></div></div></div> |
| |
| <a class="indexterm" name="d5e15234"></a> |
| <a class="indexterm" name="d5e15237"></a> |
| <a class="indexterm" name="d5e15240"></a> |
| <a class="indexterm" name="d5e15243"></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 class="link" href="ref_guide_conf_openjpa.html#openjpa.TransactionMode" title="5.69. openjpa.TransactionMode"><code class="literal">openjpa.TransactionMode |
| </code></a> configuration property. This property accepts the following |
| modes: |
| </p> |
| <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> |
| <p> |
| <code class="literal">local</code>: Perform transaction operations locally. |
| </p> |
| </li><li class="listitem"> |
| <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 class="ulink" href="http://download.oracle.com/javaee/6/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="d5e15273"></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 class="link" href="ref_guide_conf_openjpa.html#openjpa.ManagedRuntime" title="5.45. openjpa.ManagedRuntime"><code class="literal"> |
| openjpa.ManagedRuntime</code></a> configuration property. This |
| property describes an |
| <a class="ulink" href="../../apidocs/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 class="itemizedlist" style="list-style-type: disc; "><li class="listitem"> |
| <p> |
| <code class="literal">auto</code>: This is the default. It is an alias for the |
| <a class="ulink" href="../../apidocs/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 class="listitem"> |
| <p> |
| <code class="literal">invocation</code>: An alias for the |
| <a class="ulink" href="../../apidocs/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 class="listitem"> |
| <p> |
| <code class="literal">jndi</code>: An alias for the |
| <a class="ulink" href="../../apidocs/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" id="ref_guide_enterprise_transex"><p class="title"><b>Example 8.1. Configuring Transaction Manager Integration</b></p><div class="example-contents"> |
| |
| <pre class="programlisting"> |
| <property name="openjpa.TransactionMode" value="managed"/> |
| <property name="openjpa.ManagedRuntime" value="jndi(TransactionManagerName=java:/TransactionManager)"/> |
| </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> </td><td width="20%" align="center"><a accesskey="u" href="ref_guide_deploy.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ref_guide_enterprise_xa.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 8. |
| Deployment |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 3. |
| XA Transactions |
| </td></tr></table></div></body></html> |