2 Replies Latest reply on Jul 15, 2002 2:45 PM by Stefan Kuehn

    Decouple coded name from JNDI-Name (JBoss3.0 / Postgres)

    Stefan Kuehn Newbie

      Hi!

      I have set up a data source with a postgres-service.xml file.
      When i use the JNDI-name in the postgres-service.xml file, in the
      Session Bean code (coded name) for the lookup() method, the data source
      is fund (i.e. i don' get an naming exception).

      However i would like to to decouple the "coded name" (used in the session bean
      from the JNDI-name.

      I have succeded doing this for the session bean i use.
      The name of the session bean is "LogInEJB". That name listed in the deployment
      descriptor for the bean (in ejb-jar.xml).

      In the file jboss.xml the session bean is given the JNDI-name "ejb/Login".

      In a JSP-file (packed in a WAR-file) i use the coded name ejb/UserLogin.
      This coded name is "mapped" tho the JNDI-name "ejb/Login" in the file jboss-web.xml.

      I.e. the file jboss-web.xml is the glue between the coded name in the JSP-file
      (wich i never want to change) an the actual JNDI-name of the session bean.

      This works fine!

      How do i achieve this wit a datasource?

      I have tried this:

      1. I set up a datasource in a postgres-service.xml file giving it the JNDI-name "jdbc/UKontakt"
      2. In the session bean code however i use the "coded name" java:comp/env/jdbc/UKontaktDB
      3. I tried to use the file jboss.xml as the glue between the coded name and the JNDI-name like this:
      <resource-managers>
      <resource-manager res-class="javax.sql.DataSource">
      <res-name>jdbc/UKontaktDB</res-name>
      <res-jndi-name>jdbc/UKontakt</res-jndi-name>
      </resource-manager>
      </resource-managers>

      The reason for trying it this way, ist that "SUN", using the deploytool of the ref imp., puts
      the "glue" in the sun-j2ee-ri.xml file in the EAR archive (not down in the "Bean archive" jar),
      that is one level up in the archv hiearchy.

      Unfortenatly this doesn't work.

      I would appreciate any help on this on.
      Rgds.
      Stefan

        • 1. Re: Decouple coded name from JNDI-Name (JBoss3.0 / Postgres)
          Mikael Eriksson Novice

          Do something like this in your ejb-jar.xml.

          <ejb-name>YourEJBName</ejb-name>
          ..........
          <resource-ref>

          DataSource for Contacts

          <res-ref-name>jdbc/UKontaktDB</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
          </resource-ref>

          And then in the jboss.xml

          <?xml version="1.0"?>
          <!DOCTYPE jboss PUBLIC
          "-//JBoss//DTD JBOSS 3.0//EN"
          "http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd">

          <enterprise-beans>

          <ejb-name>YourEJBName</ejb-name>
          <resource-ref>
          <res-ref-name>jdbc/UKontaktDB</res-ref-name>
          <resource-name>java:/jdbc/UKontakt</resource-name>
          </resource-ref>

          </enterprise-beans>


          • 2. Re: Decouple coded name from JNDI-Name (JBoss3.0 / Postgres)
            Stefan Kuehn Newbie

            Hej Micke!

            (ok i'l continue in english ;-)

            Thanks a lot for your help!
            Your solution works fine.

            After posting my question i tried some other solutions.

            This one works too:
            No changes wer made in the jboss.xml. This file only gives my session bean an JNDI name as:

            <ejb-name>LogInEJB</ejb-name>
            <jndi-name>ejb/Login</jndi-name>


            In the file ejb-jar.xml you only have to state the JNDI name for the used coded name as ...:

            <ejb-name>YourEJBName</ejb-name>
            ...
            <resource-ref>
            <res-ref-name>jdbc/UKontaktDB</res-ref-name>
            <jndi-name>jdbc/UKontakt</jndi-name> <!-- ... as in this line -->
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>
            ...

            Here is a fragment of the postgres-service.xml just in order to make this explanation complete

            ...
            <!--embedded mbean-->


            <!-- ========== Set the JndiName ======================= -->
            jdbc/UKontakt <!-- The JNDI name used in the ejb-jar.xml! -->



            Best regards
            Stefan Kühn