title: Internal Exception: java.sql.SQLException: No database selected
body: <p>I know this question is very common among persistence users. I've visited so many the threads and questions on so many forums and still I'm not getting solution.</p>
  
  <p>I've created <em>RESTful web services from database</em> (an option in Netbeans 8.0.2). 
  I've also created connection pool and JNDI for this project. Names are properly given as shown here.</p>
  
  <p>Using EclipseLink (JPA 2.1) i.e by default
  I'm getting this kind of response: </p>
  
  <blockquote>
    <p>GET RequestFailed RequestFailed --> Status: (500)
      Response: {
      HTTP Status 500 - Internal Server Error</p>
    
    <p>type Exception report</p>
    
    <p>messageInternal Server Error</p>
    
    <p>descriptionThe server encountered an internal error that prevented it from fulfilling this request.</p>
    
    <p>exception</p>
    
    <p>javax.servlet.ServletException: javax.ejb.EJBException</p>
    
    <p>root cause</p>
    
    <p>javax.ejb.EJBException</p>
    
    <p>root cause</p>
    
    <p>javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: No database selected
    Error Code: 1046
    Call: SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users
    Query: ReadAllQuery(referenceClass=Users sql="SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users")</p>
    
    <p>root cause</p>
    
    <p>Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: No database selected
    Error Code: 1046
    Call: SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users
    Query: ReadAllQuery(referenceClass=Users sql="SELECT id, access_expires, access_token, address, bank_account_type, created, device_id, device_type, email, facebook_id, grazie_code, latitude, longitude, password, phone_number, profile_pic, refresh_expires, refresh_token, reg_id, token_created, total_balance, type_work, user_name, user_type FROM users")</p>
    
    <p>root cause</p>
    
    <p>java.sql.SQLException: No database selected</p>
    
    <p>note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1 logs.
    GlassFish Server Open Source Edition 4.1 </p>
  </blockquote>
  
  <p>my persistence.xml file is like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
    &lt;persistence-unit name="dwolla_apiPU" transaction-type="JTA"&gt;
      &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
      &lt;jta-data-source&gt;jdbc/dwolla&lt;/jta-data-source&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;shared-cache-mode&gt;ALL&lt;/shared-cache-mode&gt;
      &lt;properties&gt;
          &lt;property name="eclipselink.target-database" value="MySQL"/&gt;
          &lt;property name="eclipselink.logging.logger" value="DefaultLogger"/&gt;
          &lt;property name="eclipselink.ddl-generation" value="create-tables"/&gt;
          &lt;property name="eclipelink.logging.level" value="FINEST"/&gt;
          &lt;!-- JDBC connection properties --&gt;
          &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dwolla"/&gt;
          &lt;property name="javax.persistence.jdbc.user" value="root"/&gt;
          &lt;property name="javax.persistence.jdbc.password" value=""/&gt;
          &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;
          &lt;property name="eclipselink.jdbc.batch-writing" value="JDBC"/&gt;
          &lt;property name="javax.persistence.schema-generation.database.action" value="create-tables"/&gt;
      &lt;/properties&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Domain.xml:</p>
  
  <pre><code>&lt;resources&gt;
      &lt;jdbc-resource pool-name="__TimerPool" jndi-name="jdbc/__TimerPool" object-type="system-admin" /&gt;
      &lt;jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default" object-type="system-all" /&gt;
      &lt;jdbc-resource pool-name="APIConnectionPool" jndi-name="jdbc/dwolla" object-type="user" /&gt;
      &lt;jdbc-connection-pool name="__TimerPool" datasource-classname="org.apache.derby.jdbc.EmbeddedXADataSource" res-type="javax.sql.XADataSource"&gt;
          &lt;property value="${com.sun.aas.instanceRoot}/lib/databases/ejbtimer" name="databaseName" /&gt;
          &lt;property value=";create=true" name="connectionAttributes" /&gt;
      &lt;/jdbc-connection-pool&gt;
      &lt;jdbc-connection-pool is-isolation-level-guaranteed="false" name="DerbyPool" datasource-classname="org.apache.derby.jdbc.ClientDataSource" res-type="javax.sql.DataSource"&gt;
          &lt;property value="1527" name="PortNumber" /&gt;
          &lt;property value="APP" name="Password" /&gt;
          &lt;property value="APP" name="User" /&gt;
          &lt;property value="localhost" name="serverName" /&gt;
          &lt;property value="sun-appserv-samples" name="DatabaseName" /&gt;
          &lt;property value=";create=true" name="connectionAttributes" /&gt;
      &lt;/jdbc-connection-pool&gt;
      &lt;jdbc-connection-pool is-isolation-level-guaranteed="false" name="APIConnectionPool" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" res-type="javax.sql.DataSource"&gt;
          &lt;property name="URL" value="jdbc:mysql://localhost:3306/dwolla"/&gt;
          &lt;property value="3306" name="PortNumber" /&gt;
          &lt;property value="" name="Password" /&gt;
          &lt;property value="root" name="User" /&gt;
          &lt;property value="localhost" name="serverName" /&gt;
          &lt;property value="dwolla" name="DatabaseName" /&gt;
          &lt;property value=";create=true" name="connectionAttributes" /&gt;
      &lt;/jdbc-connection-pool&gt;
  &lt;/resources&gt;
  &lt;servers&gt;
      &lt;server name="server" config-ref="server-config"&gt;
          &lt;resource-ref ref="jdbc/__TimerPool" /&gt;
          &lt;resource-ref ref="jdbc/__default" /&gt;
          &lt;resource-ref ref="jdbc/dwolla" /&gt;
      &lt;/server&gt;
  &lt;/servers&gt;
  </code></pre>