| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>2. 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 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" title="2. Non-EE Use"><div class="titlepage"><div><div><h2 class="title" style="clear: both" id="jpa_overview_persistence_use">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> |