3 Replies Latest reply on Apr 29, 2004 6:43 AM by jonlee

    jndi datasource and ejb rules

    xs2iop

      Hello,

      I deploy a datasource : I put oracle-gaia-ds.xml on my default/deploy directory server as follow :


      <local-tx-datasource>
      <jndi-name>gaiaDS</jndi-name>
      <connection-url>jdbc:oracle:thin:@localhost:1521:gaia</connection-url>
      .....



      and access it with by a lookup in my bean :

      InitialContext jndiCntx = new InitialContext();
      DataSource ds = (DataSource)jndiCntx.lookup("java:/gaiaDS");
      and I get a jdbc connection from my datasource

      BUT

      if i use the following pattern : java:/comp/env/jdbc/gaiaDS
      as follow :


      <local-tx-datasource>
      <jndi-name>comp/env/jdbc/gaiaDS</jndi-name>
      <connection-url>jdbc:oracle:thin:@localhost:1521:gaia</connection-url>
      .....




      InitialContext jndiCntx = new InitialContext();
      DataSource ds = (DataSource)jndiCntx.lookup("java:/comp/env/jdbc/gaiaDS");
      and I CANNOT get a jdbc connection from my datasource
      with error ...

      EJBException : jdbc not bound.

      _______
      It's very strange, because jbosside console say me :
      .....bounding to JNDI name 'java:/comp/env/jdbc/gaiaDS'
      and the console on service : jboss:service=JNDIView say nothing...

      --------------
      ps : sorry Adrian, but I have search myself on net and different forum and I can clearly understand the problem.

      Best Regards
      Sébastien/Paris


        • 1. Re: jndi datasource and ejb rules

          I don't think you need to put the comp/env in the <jndi-name> tag. The container should take care of that. Not sure if that's the whole problem.

          Steve

          • 2. Re: jndi datasource and ejb rules
            xs2iop

            hello spiritualmechanic and thanks
            it's just i thank...and so, like a paranoiak, I test this suite :

            in file *-ds.xml : gaiaDS
            on lookup : lookup("java:/gaiaDS");
            --->OK

            in file *-ds.xml :...>jdbc/gaiaDS<...
            on lookup : lookup("java:/jdbc/gaiaDS");
            --->OK

            in file *-ds.xml : ...>env/jdbc/gaiaDS<...
            on lookup : lookup("java:/env/jdbc/gaiaDS");
            --->OK

            in file *-ds.xml : ...>comp/env/jdbc/gaiaDS<...
            on lookup : lookup("java:/comp/env/jdbc/gaiaDS");
            --->NOK with ex message :
            EJBException : jdbc not bound !!!!

            strange no?
            i can use the first solution with simple namespace, but i would like understand how to jboss make jndi context.

            how do you proceed yourself for naming rules?

            Regards
            bastien/xs2iop@yahoo.fr


            • 3. Re: jndi datasource and ejb rules
              jonlee

              A java:comp/env/... is a local reference or alias for a JNDI name.

              So in my ejb-jar.xml I might have:

              <resource-ref >
               <res-ref-name>jdbc/amity/AmityPool</res-ref-name>
               <res-type>javax.sql.DataSource</res-type>
               <res-auth>Application</res-auth>
               </resource-ref>

              In my jboss.xml, I would have this:
              <resource-ref>
               <res-ref-name>jdbc/amity/AmityPool</res-ref-name>
               <jndi-name>java:/AmityPool</jndi-name>
               </resource-ref>


              So my lookup in the ejb would be:
              lookup("java:comp/env/jdbc/amity/AmityPool")



              You can read more on this and the use of XDoclet to help generate these at:
              http://www.amitysolutions.com.au/documents/JBossJNDI-technote.pdf