blob: 97803b009d45aa03288c287e60c9f05b72e66084 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;7.&nbsp; EntityManagerFactory</title><base href="display"><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><link rel="home" href="manual.html" title="Apache OpenJPA 2.2 User's Guide"><link rel="up" href="jpa_overview.html" title="Part&nbsp;2.&nbsp;Java Persistence API"><link rel="prev" href="jpa_overview_persistence_use.html" title="2.&nbsp; Non-EE Use"><link rel="next" href="jpa_overview_emfactory_em.html" title="2.&nbsp; Obtaining EntityManagers"></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">Chapter&nbsp;7.&nbsp;
EntityManagerFactory
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_persistence_use.html">Prev</a>&nbsp;</td><th width="60%" align="center">Part&nbsp;2.&nbsp;Java Persistence API</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_emfactory_em.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter&nbsp;7.&nbsp; EntityManagerFactory" id="jpa_overview_emfactory"><div class="titlepage"><div><div><h2 class="title">Chapter&nbsp;7.&nbsp;
EntityManagerFactory
</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="jpa_overview_emfactory.html#jpa_overview_emfactory_obtain">1.
Obtaining an EntityManagerFactory
</a></span></dt><dt><span class="section"><a href="jpa_overview_emfactory_em.html">2.
Obtaining EntityManagers
</a></span></dt><dt><span class="section"><a href="jpa_overview_emfactory_perscontext.html">3.
Persistence Context
</a></span></dt><dd><dl><dt><span class="section"><a href="jpa_overview_emfactory_perscontext.html#jpa_overview_emfactory_perscontext_trans">3.1.
Transaction Persistence Context
</a></span></dt><dt><span class="section"><a href="jpa_overview_emfactory_perscontext.html#jpa_overview_emfactory_perscontext_extend">3.2.
Extended Persistence Context
</a></span></dt></dl></dd><dt><span class="section"><a href="jpa_overview_emf_properties.html">4.
Retrieving Properties Information
</a></span></dt><dt><span class="section"><a href="jpa_overview_emfactory_close.html">5.
Closing the EntityManagerFactory
</a></span></dt><dt><span class="section"><a href="jpa_overview_emfactory_puutil.html">6.
PersistenceUnitUtil
</a></span></dt></dl></div>
<a class="indexterm" name="d5e2106"></a>
<div class="mediaobject"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="279"><tr><td><img src="img/entitymanagerfactory.png"></td></tr></table></div>
<p>
The <code class="classname">EntityManagerFactory</code> creates <code class="classname">
EntityManager</code> instances for application use.
</p>
<div class="note" title="Note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3>
<p>
OpenJPA extends the standard <code class="classname">EntityManagerFactory</code>
interface with the
<a class="ulink" href="../javadoc/org/apache/openjpa/persistence/OpenJPAEntityManagerFactory.html" target="_top">
<code class="classname">OpenJPAEntityManagerFactory</code></a> to provide additional
functionality.
</p>
</div>
<div class="section" title="1.&nbsp; Obtaining an EntityManagerFactory"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="jpa_overview_emfactory_obtain">1.&nbsp;
Obtaining an EntityManagerFactory
</h2></div></div></div>
<a class="indexterm" name="d5e2121"></a>
<a class="indexterm" name="d5e2124"></a>
<a class="indexterm" name="d5e2127"></a>
<p>
Within a container, you will typically use <span class="emphasis"><em>injection</em></span> to
access an <code class="classname">EntityManagerFactory</code>. There are, however,
alternative mechanisms for <code class="classname">EntityManagerFactory</code>
construction.
</p>
<p>
Some vendors may supply public constructors for their <code class="classname">
EntityManagerFactory</code> implementations, but we recommend using the
Java Connector Architecture (JCA) in a managed environment, or the <code class="classname">
Persistence</code> class' <code class="methodname">createEntityManagerFactory
</code> methods in an unmanaged environment, as described in
<a class="xref" href="jpa_overview_persistence.html" title="Chapter&nbsp;6.&nbsp; Persistence">Chapter&nbsp;6, <i>
Persistence
</i></a>. These strategies allow
vendors to pool factories, cutting down on resource utilization.
</p>
<p>
<a class="indexterm" name="d5e2139"></a>
JPA allows you to create and configure an <code class="classname">
EntityManagerFactory</code>, then store it in a Java Naming and Directory
Interface (JNDI) tree for later retrieval and use.
</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_persistence_use.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jpa_overview.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_emfactory_em.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">2.&nbsp;
Non-EE Use
&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;2.&nbsp;
Obtaining EntityManagers
</td></tr></table></div></body></html>