Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/OutsideContainer"

(Using a persistence unit name)
Line 1: Line 1:
Users may also use the EntityManager API outside the container. You may use the org.eclipse.persistence.jpa.JpaHelper class to obtain an EntityManager.
+
Users may also use the EntityManager API outside the container.  
 
+
== Using a server session ==
+
<code><pre>
+
EntityManagerFactory emf = org.eclipse.persistence.jpa.JpaHelper.createEntityManagerFactory(serverSession);
+
EntityManager em = emf.createEntityManager();
+
</pre></code>
+
 
+
== Using a sessions.xml file ==
+
<code><pre>
+
EntityManagerFactory emf = org.eclipse.persistence.jpa.JpaHelper.createEntityManagerFactory(sessionName);
+
EntityManager em = emf.createEntityManager();
+
</pre></code>
+
 
+
Or you may use an EntityManager from a persistence.xml file.
+
  
 
== Using a persistence unit name ==
 
== Using a persistence unit name ==

Revision as of 10:35, 15 October 2007

Users may also use the EntityManager API outside the container.

Using a persistence unit name

EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName, propertiesMap);
EntityManager em = emf.createEntityManager();