0 Replies Latest reply on Apr 25, 2002 5:27 AM by Avinash Chugh

    Using resource-refs to datasources in EJBs

    Avinash Chugh Newbie

      Environment: jboss-3.0.0RC1_tomcat-4.0.3, Win200 Server, MS SQL-Server 7, Weblogic's Driver

      I managed to successfully setup the datasource using Weblogic's JDBC driver. THe datasource binds to (say) java:/foo and I have resource-ref's which point to the JNDI name. So I have this in my web.xml

      <resource-ref>
      <res-ref-name>jdbc/foo</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>

      and in my jboss-web.xml

      <resource-ref>
      <res-ref-name>jdbc/foo</res-ref-name>
      <jndi-name>java:/foo</jndi-name>
      </resource-ref>

      so in my code I can do (javax.sql.DataSource) ctx.lookup("java:/comp/env/jdbc/foo")..
      I have similar entries in ejb-jar.xml and jboss.xml associated with my ejb-jar's

      It turns out the resource-ref's works fine in servlets/web-layer - but when I use them in ejb's I always get errors similar to:

      ...
      java.rmi.ServerException: null
      Embedded Exception
      Table not found: FOOBAR in statement [select blah blah from FOOBAR]; nested exception is:
      javax.ejb.EJBException: null
      ...

      However if I access data-source directly in my ejb's like (javax.sql.DataSource) ctx.lookup("java:/foo") - everything is fine.
      I get same behaviour when I switched to Microsofts JDBC2 Driver.

      A resource declared with JndiName "foo" binds to "java:/foo" in jboss and just "foo" in Weblogic.
      So I know my code is more portable if I access the data-source through resource-reference.

      I had this bug - before as well with beta-release of jboss (jboss-3.0.0beta_tomcat-4.0.2).
      But I had to try again with RC1 release before reporting :-)

      Regards
      Avinash Chugh.