blob: 38c617b96322a2934f1b5c7775172f3d726eff3a [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>6.&nbsp; PersistenceUnitUtil</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.4 User's Guide"><link rel="up" href="jpa_overview_emfactory.html" title="Chapter&nbsp;7.&nbsp; EntityManagerFactory"><link rel="prev" href="jpa_overview_emfactory_close.html" title="5.&nbsp; Closing the EntityManagerFactory"><link rel="next" href="jpa_overview_em.html" title="Chapter&nbsp;8.&nbsp; EntityManager"></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">6.&nbsp;
PersistenceUnitUtil
</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">Chapter&nbsp;7.&nbsp;
EntityManagerFactory
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_em.html">Next</a></td></tr></table><hr></div><div class="section" title="6.&nbsp; PersistenceUnitUtil"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="jpa_overview_emfactory_puutil">6.&nbsp;
PersistenceUnitUtil
</h2></div></div></div>
<a class="indexterm" name="d5e2292"></a>
<pre class="programlisting">
public PersistenceUnitUtil getPersistenceUnitUtil();
</pre>
<p>
The <code class="classname">EntityManagerFactory</code> method
<code class="methodname">getPersistenceUnitUtil</code> provides access to a
<code class="classname">PersistenceUnitUtil</code> utility. <code class="classname">PersistenceUnitUtil</code>
can be used to obtain the identity of a managed object and determine the load
state of the entity or one of its attributes. If the object is not
managed by one of the entity managers created from the entity manager factory
from which the utility was obtained, the <code class="methodname">getIdentifier</code> method will
return null and the <code class="methodname">isLoaded</code> methods will return false.
</p><pre class="programlisting">
EntityManagerFactory emf = Persistence.createEntityManagerFactory();
PersistenceUnitUtil puUtil = emf.getPersistenceUnitUtil();
if (puUtil.getIdentifier(deptEntity) == null) {
throw new Exception("Identity is not valid.");
}
if (!puUtil.isLoaded(deptEntity, "employees")) {
throw new Exception("Employees not loaded.");
}
</pre><p>
</p>
</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_emfactory.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_em.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.&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;Chapter&nbsp;8.&nbsp;
EntityManager
</td></tr></table></div></body></html>