Jump to: navigation, search

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

(New page: You may use the org.eclipse.persistence.jpa.JpaHelper class to obtain an EntityManager. == Using a server session == <code><pre> EntityManagerFactory emf = org.eclipse.persistence.jpa.Jpa...)
 
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
You may use the org.eclipse.persistence.jpa.JpaHelper class to obtain an EntityManager.
+
[[Category:EclipseLink/Example/JPA|NativeMetadata]]
 +
 
 +
You may use the [http://www.eclipse.org/eclipselink/api/1.2/org/eclipse/persistence/jpa/JpaHelper.html <code>org.eclipse.persistence.jpa.JpaHelper</code>] class to obtain an EntityManager.
  
 
== Using a server session ==
 
== Using a server session ==
<code><pre>
+
<source lang="java">
EntityManagerFactory emf = org.eclipse.persistence.jpa.JpaHelper.createEntityManagerFactory(serverSession);
+
EntityManagerFactory emf = JpaHelper.createEntityManagerFactory(serverSession);
 
EntityManager em = emf.createEntityManager();
 
EntityManager em = emf.createEntityManager();
</pre></code>
+
</source>
  
 
== Using a sessions.xml file ==
 
== Using a sessions.xml file ==
<code><pre>
+
 
EntityManagerFactory emf = org.eclipse.persistence.jpa.JpaHelper.createEntityManagerFactory(sessionName);
+
If you want to use EclipseLink or Oracle TopLink's native XML metadata within EclipseLink JPA this can be accomplished using API:
 +
 
 +
<source lang="java">
 +
EntityManagerFactory emf = JpaHelper.createEntityManagerFactory(sessionName);
 
EntityManager em = emf.createEntityManager();
 
EntityManager em = emf.createEntityManager();
</pre></code>
+
</source>
 +
 
 +
or through the use of persistence unit properties in your persistence.xml:
 +
 
 +
<source lang="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>
 +
</source>

Latest revision as of 12:04, 26 November 2009


You may use the org.eclipse.persistence.jpa.JpaHelper class to obtain an EntityManager.

Using a server session

EntityManagerFactory emf = 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 = 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>