| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>7. 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 8. EntityManager"><link rel="prev" href="jpa_overview_em_query.html" title="6. Query Factory"><link rel="next" href="jpa_overview_trans.html" title="Chapter 9. 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. |
| Closing |
| </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_em_query.html">Prev</a> </td><th width="60%" align="center">Chapter 8. |
| EntityManager |
| </th><td width="20%" align="right"> <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. |
| Closing |
| </h2></div></div></div><a class="indexterm" name="d0e5313"></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> </td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_em.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jpa_overview_trans.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6. |
| Query Factory |
| </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 9. |
| Transaction |
| </td></tr></table></div></body></html> |