3 Replies Latest reply on Nov 20, 2003 5:54 AM by jamesstrachan

    Deploy multiple instances, same EJB

    stanaccy

      Ok, after an hour or two of head banging against table top, is this possible:

      Can we deploy multiple instances of the same stateless session EJB with different JNDI names? (so that we can use the same session bean against different datasources, please dont ask why, its just the way things are here..)

      We came across this, and it seems to suggest we can:

      http://jboss.sourceforge.net/doc-24/ch05s10.html

      But... when we do this, we only see a single entry in the JNDI tree for the last entry in the jboss.xml file.

      We are using: JBoss 3.2.1, SunOS 5.8.

      ejb-jar.xml:

      ...blah blah

      <ejb-name>MyEJB</ejb-name>
      <home...blah blah blah>
      ...
      ...


      jboss.xml:


      blah blah blah

      <ejb-name>MyEJB</ejb-name>
      <jndi-name>One</jndi-name>


      <ejb-name>MyEJB</ejb-name>
      <jndi-name>Two</jndi-name>

      blah blah


      If so, please post up an example ejb-jar.xml and a jboss.xml.

      If not, should we be able to? (i.e. is this a bug?)

      Nick

        • 1. Re: Deploy multiple instances, same EJB
          jamesstrachan

          I poked around in the source code some time ago.

          From memory, an internal reference is created for each session bean defined in ejb-jar.xml. The jndi-name attribute is set as default to the ejb-name, and then overwritten if a reference is found in jboss.xml.

          So each reference in jboss.xml will overwrite any previous reference - the behaviour that you describe.

          You should (I haven't tried this) be able to get round this by defining multiple EJB's that use the same class - as shown below :-


          ejb-jar.xml:

          ...blah blah

          <ejb-name>MyEJBOne</ejb-name>
          <home...MyEJBHome>
          ...
          ...


          <ejb-name>MyEJBTwo</ejb-name>
          <home...MyEJBHome>
          ...
          ...


          jboss.xml:


          blah blah blah

          <ejb-name>MyEJBOne</ejb-name>
          <jndi-name>One</jndi-name>


          <ejb-name>MyEJBTwo</ejb-name>
          <jndi-name>Two</jndi-name>

          blah blah


          It shouldn't take you long to find out if this works.

          James

          • 2. Re: Deploy multiple instances, same EJB
            stanaccy

            Thanks James, thats a similar idea to what we came up with, but it makes our xdoclet generation a little more complex (if its even possible), as well as making the deployment more coupled with development.

            Do you know if its supposed to work as we are expecting, or its correctly only giving us a single instance when we define multiple bean/jndi mappings in JBoss.xml ? (The docs sorta suggest that its possible).

            Thanks again

            Nick

            • 3. Re: Deploy multiple instances, same EJB
              jamesstrachan

              Nick,

              I tweaked my deployment files to try this out. See the attached ejb-jar.xml and jboss.xml.

              To summarise the results of testing :-

              1. Creating another EJB milton/errors/logger2 with the same set of classes results in two parallel deployments of the same bean under different names. See definition in ejb-jar.xml.


              2. Looking in jboss.xml, the first session bean definition reassigns the jndi name of logger2 to redirectlogger.

              3. The second session bean definition overwrites the reassignment in the first definition. So you only have one JNDI name for the logger2 bean - redirectloggeragain.