| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>2. Obtaining EntityManagers</title><link rel="stylesheet" href="css/docbook.css" type="text/css"><base href="display"><meta name="generator" content="DocBook XSL Stylesheets V1.72.0"><link rel="start" href="manual.html" title="Apache OpenJPA 2.1 User's Guide"><link rel="up" href="jpa_overview_emfactory.html" title="Chapter 7. EntityManagerFactory"><link rel="prev" href="jpa_overview_emfactory.html" title="Chapter 7. EntityManagerFactory"><link rel="next" href="jpa_overview_emfactory_perscontext.html" title="3. Persistence Context"></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. |
| Obtaining EntityManagers |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_emfactory.html">Prev</a> </td><th width="60%" align="center">Chapter 7. |
| EntityManagerFactory |
| </th><td width="20%" align="right"> <a accesskey="n" href="jpa_overview_emfactory_perscontext.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="jpa_overview_emfactory_em"></a>2. |
| Obtaining EntityManagers |
| </h2></div></div></div><a class="indexterm" name="d0e4461"></a><a class="indexterm" name="d0e4468"></a><pre class="programlisting"> |
| public EntityManager createEntityManager(); |
| public EntityManager createEntityManager(Map map); |
| </pre><p> |
| The two <code class="methodname">createEntityManager</code> methods above create a new |
| <code class="classname">EntityManager</code> each time they are invoked. The optional |
| <code class="classname">Map</code> is used to supply vendor-specific settings. If you |
| have configured your implementation for JTA transactions and a JTA transaction |
| is active, the returned <code class="classname">EntityManager</code> will be |
| synchronized with that transaction. |
| </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p> |
| OpenJPA recognizes the following string keys in the map supplied to <code class="methodname"> |
| createEntityManager</code>: |
| </p><div class="itemizedlist"><ul type="disc"><li><p> |
| <code class="literal">openjpa.ConnectionUserName</code> |
| </p></li><li><p> |
| <code class="literal">openjpa.ConnectionPassword</code> |
| </p></li><li><p> |
| <code class="literal">openjpa.ConnectionRetainMode</code> |
| </p></li><li><p> |
| <code class="literal">openjpa.TransactionMode</code> |
| </p></li><li><p> |
| <code class="literal">openjpa.<property></code>, where <span class="emphasis"><em><property> |
| </em></span> is any JavaBean property of the |
| <a xmlns:xlink="http://www.w3.org/1999/xlink" href="../javadoc/org/apache/openjpa/persistence/OpenJPAEntityManager.html" target="_top"> |
| <code class="classname"> |
| org.apache.openjpa.persistence.OpenJPAEntityManager</code></a>. |
| </p></li></ul></div><p> |
| The last option uses reflection to configure any property of OpenJPA's |
| <code class="classname">EntityManager</code> implementation with the value supplied in |
| your map. The first options correspond exactly to the same-named OpenJPA |
| configuration keys described in <a href="ref_guide_conf.html" title="Chapter 2. Configuration">Chapter 2, <i xmlns:xlink="http://www.w3.org/1999/xlink"> |
| Configuration |
| </i></a> of the |
| Reference Guide. |
| </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jpa_overview_emfactory.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_emfactory.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jpa_overview_emfactory_perscontext.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 7. |
| EntityManagerFactory |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> 3. |
| Persistence Context |
| </td></tr></table></div></body></html> |