blob: c01de3bf8c0ea0ebe13d024b391baa41892feceb [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Chapter&nbsp;8.&nbsp; EntityManager</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 1.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_emfactory_close.html" title="4.&nbsp; Closing the EntityManagerFactory"><link rel="next" href="jpa_overview_em_lifecycle.html" title="2.&nbsp; Entity Lifecycle Management"></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;8.&nbsp;
EntityManager
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_emfactory_close.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_em_lifecycle.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en" id="jpa_overview_em"><div class="titlepage"><div><div><h2 class="title"><a name="jpa_overview_em"></a>Chapter&nbsp;8.&nbsp;
EntityManager
</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="jpa_overview_em.html#jpa_overview_em_trans">1.
Transaction Association
</a></span></dt><dt><span class="section"><a href="jpa_overview_em_lifecycle.html">2.
Entity Lifecycle Management
</a></span></dt><dt><span class="section"><a href="jpa_overview_em_lifeexamples.html">3.
Lifecycle Examples
</a></span></dt><dt><span class="section"><a href="jpa_overview_em_identity.html">4.
Entity Identity Management
</a></span></dt><dt><span class="section"><a href="jpa_overview_em_cache.html">5.
Cache Management
</a></span></dt><dt><span class="section"><a href="jpa_overview_em_query.html">6.
Query Factory
</a></span></dt><dt><span class="section"><a href="jpa_overview_em_closing.html">7.
Closing
</a></span></dt></dl></div><a class="indexterm" name="d0e4528"></a><div class="mediaobject"><table border="0" summary="manufactured viewport for HTML img" cellspacing="0" cellpadding="0" width="189"><tr><td><img src="img/entitymanager.png"></td></tr></table></div><p>
The diagram above presents an overview of the <code class="classname">EntityManager
</code> interface. For a complete treatment of the <code class="classname">
EntityManager</code> API, see the
<a xmlns:xlink="http://www.w3.org/1999/xlink" href="http://java.sun.com/javaee/5/docs/api/javax/persistence/EntityManager.html" target="_top">
Javadoc</a> documentation. Methods whose parameter signatures consist of
an ellipsis (...) are overloaded to take multiple parameter types.
</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
OpenJPA extends the standard <code class="classname">EntityManager</code> interface with
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> interface to provide additional functionality.
</p></div><p>
The <code class="classname">EntityManager</code> is the primary interface used by
application developers to interact with the JPA runtime. The methods
of the <code class="classname">EntityManager</code> can be divided into the following
functional categories:
</p><div class="itemizedlist"><ul type="disc"><li><p>
<code class="classname">Transaction</code> association.
</p></li><li><p>
Entity lifecycle management.
</p></li><li><p>
Entity identity management.
</p></li><li><p>
Cache management.
</p></li><li><p>
<code class="classname">Query</code> factory.
</p></li><li><p>
Closing.
</p></li></ul></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="jpa_overview_em_trans"></a>1.&nbsp;
Transaction Association
</h2></div></div></div><a class="indexterm" name="d0e4594"></a><a class="indexterm" name="d0e4601"></a><pre class="programlisting">
public EntityTransaction getTransaction ();
</pre><p>
Every <code class="classname">EntityManager</code> has a one-to-one relation with an
<a href="jpa_overview_trans.html" title="Chapter&nbsp;9.&nbsp; Transaction"><code class="classname">EntityTransaction</code>
</a> instance. In fact, many vendors use a single class to implement both the
<code class="classname">EntityManager</code> and <code class="classname">EntityTransaction
</code> interfaces. If your application requires multiple concurrent
transactions, you will use multiple <code class="classname">EntityManager</code>s.
</p><p>
You can retrieve the <code class="classname">EntityTransaction</code> associated with an
<code class="classname">EntityManager</code> through the <code class="methodname">getTransaction
</code> method. Note that most JPA implementations can
integrate with an application server's managed transactions. If you take
advantage of this feature, you will control transactions by declarative
demarcation or through the Java Transaction API (JTA) rather than through the
<code class="classname">EntityTransaction</code>.
</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_close.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_em_lifecycle.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4.&nbsp;
Closing the 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;2.&nbsp;
Entity Lifecycle Management
</td></tr></table></div></body></html>