|  | <html><head> | 
|  | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> | 
|  | <title>2.  Non-EE Use</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_persistence.html" title="Chapter 6.  Persistence"><link rel="prev" href="jpa_overview_persistence.html" title="Chapter 6.  Persistence"><link rel="next" href="jpa_overview_emfactory.html" title="Chapter 7.  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.  | 
|  | Non-EE Use | 
|  | </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="jpa_overview_persistence.html">Prev</a> </td><th width="60%" align="center">Chapter 6.  | 
|  | Persistence | 
|  | </th><td width="20%" align="right"> <a accesskey="n" href="jpa_overview_emfactory.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_persistence_use"></a>2.  | 
|  | 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 6.2.  | 
|  | 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> </td><td width="20%" align="center"><a accesskey="u" href="jpa_overview_persistence.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="jpa_overview_emfactory.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 6.  | 
|  | Persistence | 
|  |  </td><td width="20%" align="center"><a accesskey="h" href="manual.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 7.  | 
|  | EntityManagerFactory | 
|  | </td></tr></table></div></body></html> |