3 Replies Latest reply on Feb 10, 2006 1:04 AM by Mike Thomason

    JNDI Datasource Lookup in MDB Returning wrong Datasource

    Mike Thomason Newbie

      I am running JBoss 4.0.3 SP1 and I am having problems with the implementation of a message-driven bean.

      I have the following data source entry in my application-ds.xml file:

      <local-tx-datasource>
       <jndi-name>TAP_DATASOURCE</jndi-name>
       <connection-url>jdbc:oracle:thin:@cncux42:1522:dev1</connection-url>
       <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
       <user-name>tap</user-name>
       <password>tap_dev1</password>
      </local-tx-datasource>



      I am deploying the application as an EAR file containing the WAR and EJB jar files. Code running within the WAR web application has no problems performing the lookup and returning the correct datasource.

      Code executed from within the Message-Driven bean however will not return the TAP_DATASOURCE datasource, but instead returns the DefaultDS, which is mapped to a hypersonic datasource that is loaded.

      The code performing the lookup is as follows:

      Object rc = initCtx.lookup( "java:/comp/env/" );
      Context envCtx = (Context)rc;
      rc = envCtx.lookup( "jdbc/TAP_DATASOURCE" );


      For the WAR, my web.xml contains:
      <resource-ref>
       <res-ref-name>jdbc/TAP_DATASOURCE</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
      </resource-ref>
      
      <resource-ref>
       <res-ref-name>jdbc/DATATRON_DATASOURCE</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
      </resource-ref>



      and my jboss-web.xml contains:
      <resource-ref>
       <res-ref-name>jdbc/TAP_DATASOURCE</res-ref-name>
       <jndi-name>java:/TAP_DATASOURCE</jndi-name>
      </resource-ref>
      
      <resource-ref>
       <res-ref-name>jdbc/DATATRON_DATASOURCE</res-ref-name>
       <jndi-name>java:/DATATRON_DATASOURCE</jndi-name>
      </resource-ref>



      My ejb-jar.xml file for the MDB EJB jar file contains the following within the <message-driven> tag:
      <resource-ref>
       <res-ref-name>jdbc/TAP</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
      </resource-ref>



      As for the jboss.xml for the MDB EJB jar file, I have tried a couple of configurations based on different things I have found on Google, but I get
      the same results in each case.

      The latest attempt I used the following in the <message-driven> tag:
      <resource-ref>
       <res-ref-name>jdbc/TAP</res-ref-name>
       <jndi-name>TAP</jndi-name>
      </resource-ref>