title: Java persistence API: Glassfish tries to use derby instead of MySQL?
body: <p>I wrote the following <strong>persistence.xml</strong> for a <strong>glassfish</strong> webapp: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;persistence 
      xmlns="http://java.sun.com/xml/ns/persistence" 
      version="2.1"&gt;
  
     &lt;persistence-unit name="mypu" transaction-type="RESOURCE_LOCAL"&gt;
       &lt;description&gt;my&lt;/description&gt;
       &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
       &lt;class&gt;my.OntClass&lt;/class&gt;
  
       &lt;properties&gt;
  
         &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/user_lindenb"/&gt;
         &lt;property name="javax.persistence.jdbc.user" value="appuser"/&gt;
         &lt;property name="javax.persistence.jdbc.password" value="apppassword"/&gt;
         &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;
         &lt;property name="eclipselink.weaving" value="false"/&gt;&lt;!--  http://java.dzone.com/articles/jpa-performance-optimization --&gt;
          &lt;property name="eclipselink.target-database" value="MySQL"/&gt;
          &lt;property name="eclipselink.logging.level" value="ALL"/&gt;
          &lt;property name="eclipselink.logging.parameters" value="false"/&gt;
       &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>The MySQL server is running and I can connect to the MySQL server from a servlet using a:</p>
  
  <pre><code>@Resource (name="jdbc/MysqlDS" )
  javax.sql.DataSource mysqlDS;
  </code></pre>
  
  <p>Now, I want to use the persistence API. But when I want to deploy my application it raises the following error:</p>
  
  <pre><code>remote failure: Error occurred during deployment: Exception while preparing the app : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
  Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.
  </code></pre>
  
  <p>As far as I understand, it tries to connect to Derby instead of MySQL?</p>
  
  <pre><code>glassfish log:
  (...) 
  Caused by: org.apache.derby.client.am.DisconnectException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused.
      at org.apache.derby.client.net.NetAgent.&lt;init&gt;(Unknown Source)
      at org.apache.derby.client.net.NetConnection.newAgent_(Unknown Source)
      at org.apache.derby.client.am.Connection.initConnection(Unknown Source)
      at org.apache.derby.client.am.Connection.&lt;init&gt;(Unknown Source)
      at org.apache.derby.client.net.NetConnection.&lt;init&gt;(Unknown Source)
      at org.apache.derby.client.net.NetConnection40.&lt;init&gt;(Unknown Source)
      at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
      at org.apache.derby.jdbc.ClientDataSource.getConnectionX(Unknown Source)
      ... 71 more
  Caused by: java.net.ConnectException: Connection refused
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:579)
      at java.net.Socket.connect(Socket.java:528)
      at java.net.Socket.&lt;init&gt;(Socket.java:425)
      at java.net.Socket.&lt;init&gt;(Socket.java:208)
      at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:271)
      at org.apache.derby.client.net.OpenSocketAction.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      ... 79 more
  (...)
  </code></pre>
  
  <p>How can I fix this?</p>
  
  <p>Thanks.</p>