blob: e7df9fff91f8c491399abe313dd316cecd7d00c0 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>2.&nbsp; Non-EE Use</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_persistence.html" title="Chapter&nbsp;6.&nbsp; Persistence"><link rel="prev" href="jpa_overview_persistence.html" title="Chapter&nbsp;6.&nbsp; Persistence"><link rel="next" href="jpa_overview_emfactory.html" title="Chapter&nbsp;7.&nbsp; EntityManagerFactory"></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">2.&nbsp;
Non-EE Use
</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_persistence.html">Prev</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;6.&nbsp;
Persistence
</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_emfactory.html">Next</a></td></tr></table><hr></div><div class="section" title="2.&nbsp; Non-EE Use"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="jpa_overview_persistence_use">2.&nbsp;
Non-EE Use
</h2></div></div></div>
<p>
The example below demonstrates the <code class="classname">Persistence</code> class in
action. You will typically execute code like this on application startup, then
cache the resulting factory for future use. This bootstrapping code is only
necessary in non-EE environments; in an EE environment <code class="classname">
EntityManagerFactories</code> are typically injected.
</p>
<div class="example"><a name="jpa_overview_persistence_getemfactory"></a><p class="title"><b>Example&nbsp;6.2.&nbsp;
Obtaining an EntityManagerFactory
</b></p><div class="example-contents">
<pre class="programlisting">
// if your persistence.xml file does not contain all settings already, you
// can add vendor settings to a map
Properties props = new Properties();
...
// create the factory defined by the "openjpa" entity-manager entry
EntityManagerFactory emf = Persistence.createEntityManagerFactory("openjpa", props);
</pre>
</div></div><br class="example-break">
</div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="jpa_overview_persistence.html">Prev</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_persistence.html">Up</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="jpa_overview_emfactory.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter&nbsp;6.&nbsp;
Persistence
&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;7.&nbsp;
EntityManagerFactory
</td></tr></table></div></body></html>