blob: e287167333d65bd20c459a440a372b40faa287e2 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>2.&nbsp; Obtaining EntityManagers</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="jpa_overview_emfactory.html" title="Chapter&nbsp;7.&nbsp; EntityManagerFactory"><link rel="prev" href="jpa_overview_emfactory.html" title="Chapter&nbsp;7.&nbsp; EntityManagerFactory"><link rel="next" href="jpa_overview_emfactory_perscontext.html" title="3.&nbsp; 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.&nbsp;
Obtaining EntityManagers
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_emfactory.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;7.&nbsp;
EntityManagerFactory
</th><td width="20%" align="right">&nbsp;<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.&nbsp;
Obtaining EntityManagers
</h2></div></div></div><a class="indexterm" name="d0e4225"></a><a class="indexterm" name="d0e4232"></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 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.&lt;property&gt;</code>, where <span class="emphasis"><em>&lt;property&gt;
</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&nbsp;2.&nbsp; Configuration">Chapter&nbsp;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>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_emfactory.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_emfactory_perscontext.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;7.&nbsp;
EntityManagerFactory
&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;
Persistence Context
</td></tr></table></div></body></html>