title: Database settings in persistence.xml not used
body: <p>I'm new to JPA, and to try to teach myself, I'm setting up a tiny web application and deploying to Glassfish 3.1.</p>
  
  <p>JPA works fine when I refer to a JNDI DataSource in persistence.xml, such as this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
               version="1.0"&gt;
      &lt;persistence-unit name="foo" transaction-type="JTA"&gt;
          &lt;jta-data-source&gt;jdbc/foo&lt;/jta-data-source&gt;
          &lt;class&gt;my.app.Foo&lt;/class&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>But as far as I understand, it is supposed to be possible to put all my database connection settings into properties in persistence.xml. This may not be good practice, but it seems like it could be handy when I'm just experimenting, and perhaps during unit testing.</p>
  
  <p>However, when I follow the examples I have found for this, persistence.xml seems to be just ignored and instead the default container-managed DataSource, jndi/__default is used. This is a Derby instance that is not running.</p>
  
  <p>I've tried this file for an ephemeral in-memory Derby instance:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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 http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0"&gt;
      &lt;persistence-unit name="foo" transaction-type="JTA"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;class&gt;my.app.Foo&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:derby:memory:NxtMv;create=true"/&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/&gt;
              &lt;property name="javax.persistence.jdbc.user" value=""/&gt;
              &lt;property name="javax.persistence.jdbc.password" value=""/&gt;
              &lt;property name="eclipselink.ddl-generation" value="create-tables"/&gt;
              &lt;property name="eclipselink.ddl-generation.output-mode" value="database" /&gt;
              &lt;property name="eclipselink.logging.level" value="INFO"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I have also tried this for a PostgreSQL server (which works when accessed through JNDI):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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 http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0"&gt;
      &lt;persistence-unit name="foo" transaction-type="JTA"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;class&gt;my.app.Foo&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/foo"/&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/&gt;
              &lt;property name="javax.persistence.jdbc.user" value="myuser"/&gt;
              &lt;property name="javax.persistence.jdbc.password" value="secret"/&gt;
              &lt;property name="eclipselink.ddl-generation" value="create-tables"/&gt;
              &lt;property name="eclipselink.ddl-generation.output-mode" value="database" /&gt;
              &lt;property name="eclipselink.logging.level" value="INFO"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>There's probably some irrelevant cruft in those files which has accumulated during my countless tries and retries.</p>
  
  <p>What am I missing here?</p>