title: persistence.xml with Glassfish 3.1.1
body: <p>I am very new to glassfish, JPA and so on and I have really problems with setting that up. What I am planning to do is a simple RESTful service with a persistent backend. I am using glassfish3 as application server and already deployed a simple REST service with the jersey-library. Now I want to provide access to a database via JPA. Glassfish is shipped with JavaDB/derby and EclipseLink, is that right? So, I want to use that :-)</p>
  
  <p>I created a persistence.xml in META-INF:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="1.0"
      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
                          http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&gt;
    &lt;persistence-unit name="myPU" transaction-type="JTA"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties&gt;
        &lt;property name="javax.persistence.jdbc.driver"   value="org.apache.derby.jdbc.ClientDataSource" /&gt; &lt;!-- org.apache.derby.jdbc.EmbeddedDriver --&gt;
        &lt;property name="javax.persistence.jdbc.url"      value="jdbc:derby://localhost:1527/sample;create=true" /&gt;
        &lt;property name="javax.persistence.jdbc.user"     value="APP" /&gt;
        &lt;property name="javax.persistence.jdbc.password" value="APP" /&gt;
        &lt;property name="eclipselink.ddl-generation"      value="create-tables" /&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Then I created a field in my resource, where I want to access/store som data:</p>
  
  <pre><code>@PersistenceUnit(unitName = "myPU")
  EntityManagerFactory emf;
  </code></pre>
  
  <p>But "emf" is always NULL :-(</p>
  
  <p>I guess that my persistence.xml is not configured appropriate.</p>
  
  <p>Would be really glad if someone has a hint, what I am doing wrong...</p>
  
  <p>thanks!</p>