1 Reply Latest reply on May 13, 2007 1:21 PM by jaikiran

    NullPointerException getting Datasource connection

    cdmunoz

      Inside the same project I'm using both EJB 3.0 (with configuration in persistence.xml) and DAO with JDBC. I don't have problems accessing objects with EJB beacuse they are on a particular module, but I can't access any object with JDBC.
      I got configured my oracle-xa-ds.xml as follow:
      <xa-datasource>
      <jndi-name>fmarketdb</jndi-name> . . .
      for EJB and
      <xa-datasource>
      <jndi-name>it</jndi-name> . . .
      for JDBC.
      Jboss Application Server (jboss-4.0.3_SP1) inits the datasource without problems.

      My jboss-web.xml:
      <jboss-web>
      <resource-ref>
      <res-ref-name>jdbc/it</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/it</jndi-name>
      </resource-ref>
      </jboss-web>


      My web.xml:
      <jboss-web>
      <resource-ref>
      <res-ref-name>jdbc/it</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/it</jndi-name>
      </resource-ref>
      </jboss-web>


      My Java source (jdk1.5.0_08):
      protected Connection getConnection() throws Exception {
      Context initCtx = new InitialContext();
      Context envCtx = (Context) initCtx.lookup("java:comp/env");
      DataSource ds = (DataSource)envCtx.lookup("jdbc/it");
      Connection conn = ds.getConnection();
      conn.setAutoCommit(false);
      return conn;
      }


      When I try to access an object through JDBC, I got the next error:
      java.lang.NullPointerException at com.ceiba.corporativo.root.bo.BussinessLogicAbs.getConnection(BussinessLogicAbs.java:57)
      and this because envCtx.lookup("jdbc/it") returns null and I don't understand why? Those are independent modules.
      Can somebody help me please?
      Does affect EJB configuration inside Jboss?