title: JNDI lookup failed for the resource Type: javax.sql.DataSource
body: <p>The error is in the title. It's very strange, because I was doing some modifications to the xhtml code and its beans, turning the glassfish server on and off and on again several times, and suddenly this error appeared. I did not touch the web.xml or any of those types of files while I was working, just the xhtml and its beans.</p>
  
  <p>Error message: </p>
  
  <pre><code>Severe:   JNDI lookup failed for the resource: Name: JPATestPU, Lookup: java:app/jpaDB, Type: javax.sql.DataSource.
  Severe:   Exception while deploying the app [JPAAdvanced]
  Severe:   Exception during lifecycle processing
  
  org.glassfish.deployment.common.DeploymentException: JNDI lookup failed for the resource: Name: [JPATestPU], Lookup: [java:app/jpaDB], Type: [javax.sql.DataSource]
      at[...]
  Caused by: javax.naming.NamingException: Lookup failed for 'java:app/jpaDB' in SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
      at[...]
  Caused by: javax.naming.NamingException: Invocation exception: Got null ComponentInvocation 
      at[...]
  
  Severe:   Exception while deploying the app [JPAAdvanced] : JNDI lookup failed for the resource: Name: [JPATestPU], Lookup: [java:app/jpaDB], Type: [javax.sql.DataSource]
  javax.naming.NamingException: Lookup failed for 'java:app/jpaDB' in SerialContext[myEnv={java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
      at[...]
  Caused by: javax.naming.NamingException: Invocation exception: Got null ComponentInvocation 
      at[...]
  </code></pre>
  
  <p>The web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;faces/index.xhtml&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The glasfish-resources.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd"&gt;
  &lt;resources&gt;
      &lt;jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="org.postgresql.ds.PGSimpleDataSource" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="post-gre-sql_jpaDB_postgresPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false"&gt;
  
          &lt;property name="serverName" value="localhost"/&gt;
          &lt;property name="portNumber" value="5432"/&gt;
          &lt;property name="databaseName" value="jpaDB"/&gt;
          &lt;property name="User" value="postgres"/&gt;
          &lt;property name="Password" value="*****"/&gt;
          &lt;property name="URL" value="jdbc:postgresql://localhost:5432/jpaDB"/&gt;
          &lt;property name="driverClass" value="org.postgresql.Driver"/&gt;
      &lt;/jdbc-connection-pool&gt;
      &lt;jdbc-resource enabled="true" jndi-name="java:app/jpaDB" object-type="user" pool-name="post-gre-sql_jpaDB_postgresPool"/&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>If there is anything else to add, please say so and I will add it.</p>