Skip to main content

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.

Jump to: navigation, search

EclipseLink/Examples/JPA/NativeMetadata


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

If you want to use EclipseLink or Oracle TopLink's native XML metadata within EclipseLink JPA this can be accomplished using API:

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

or through the use of persistence unit properties in your persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd"
          version="1.0">
    <persistence-unit name="my-app" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <properties>
             <property name="eclipselink.sessions-xml" value="org/my-app/persistence/sessions.xml"/>
             <property name="eclipselink.session-name" value="my-app"/>
        </properties>
    </persistence-unit>
</persistence>

Back to the top