blob: 4ea2bfb90fc059fd0d345220ec10dbe4fae08f77 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>7.&nbsp; Closing</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_em.html" title="Chapter&nbsp;8.&nbsp; EntityManager"><link rel="prev" href="jpa_overview_em_query.html" title="6.&nbsp; Query Factory"><link rel="next" href="jpa_overview_trans.html" title="Chapter&nbsp;9.&nbsp; Transaction"></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">7.&nbsp;
Closing
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_em_query.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;8.&nbsp;
EntityManager
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_trans.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_em_closing"></a>7.&nbsp;
Closing
</h2></div></div></div><a class="indexterm" name="d0e5307"></a><pre class="programlisting">
public boolean isOpen();
public void close();
</pre><p>
When an <code class="classname">EntityManager</code> is no longer needed, you should
call its <code class="methodname">close</code> method. Closing an <code class="classname">
EntityManager</code> releases any resources it is using. The persistence
context ends, and the entities managed by the <code class="classname">EntityManager
</code> become detached. Any <code class="classname">Query</code> instances the
<code class="classname">EntityManager</code> created become invalid. Calling any method
other than <code class="methodname">isOpen</code> on a closed <code class="classname">EntityManager
</code> results in an <code class="classname">IllegalStateException</code>. You
cannot close a <code class="classname">EntityManager</code> that is in the middle of a
transaction.
</p><p>
If you are in a managed environment using injected entity managers, you should
not close them.
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jpa_overview_em_query.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_em.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_trans.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6.&nbsp;
Query Factory
&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top">&nbsp;Chapter&nbsp;9.&nbsp;
Transaction
</td></tr></table></div></body></html>