Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/JPA/OutsideContainer"
< EclipseLink | Examples | JPA
(→Using a persistence unit name) |
|||
Line 18: | Line 18: | ||
<code><pre> | <code><pre> | ||
EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName, propertiesMap); | EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName, propertiesMap); | ||
− | EntityManager em = | + | EntityManager em = emf.createEntityManager(); |
</pre></code> | </pre></code> | ||
− | |||
− |
Revision as of 10:31, 15 October 2007
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();
Using a sessions.xml file
EntityManagerFactory emf = org.eclipse.persistence.jpa.JpaHelper.createEntityManagerFactory(sessionName);
EntityManager em = emf.createEntityManager();
Or you may use an EntityManager from a persistence.xml file.
Using a persistence unit name
EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName, propertiesMap);
EntityManager em = emf.createEntityManager();