Jump to: navigation, search

EclipseLink/Examples/JPA/OutsideContainer

< EclipseLink‎ | Examples‎ | JPA
Revision as of 09:13, 15 October 2007 by Guy.pelletier.oracle.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Users may also use the EntityManager API outside the container. You may use the org.eclipse.persistence.jpa.JpaHelper class to obtain an EntityManager.

Using a server session

EntityManagerFactory emf = org.eclipse.persistence.jpa.JpaHelper.createEntityManagerFactory(serverSession);
EntityManager em = emf.createEntityManager();
<code>

Using a sessions.xml file

<code>
EntityManagerFactory emf = org.eclipse.persistence.jpa.JpaHelper.createEntityManagerFactory(sessionName);
EntityManager em = emf.createEntityManager();
<code>

Or you may use an EntityManager from a persistence.xml file.

Using a persistence unit name

<code>
EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName, propertiesMap);
EntityManager em = create.getEntityManager();

Users will then need to specify the database properties in the propertiesMap and are resonsible for building their persistence.xml file and having it available on the classpath.