6 Replies Latest reply on Feb 25, 2003 3:34 PM by McGee

    Multiple EJBs with same name in an EAR?

    McGee Newbie

      The J2EE spec (J2EE.5.3.2 Application Assembler’s Responsibilities) makes it clear that we shouldn't have to come up with unique names for all EJBs within an application, and it provides the <ejb-link> subelement of <ejb-ref> to resolve namespace clashes.

      However, I just made a simple little EAR with two simple EJBs, each in a separate JAR, each with the same name. JBoss barfed while deploying the second EJB, saying the name was taken.

      I would never dare suggest that JBoss is failing to meet the spec, so I'm guessing that I'm doing something wrong or misunderstanding something. Any help?

      Thanks a lot,
      McGee

        • 1. Re: Multiple EJBs with same name in an EAR?
          Adrian Brock Master

          Post your deployment descriptors.

          Have you changed the <jndi-name>s in jboss.xml?
          Those must be unique, jboss uses the <ejb-name>
          as the <jndi-name> if you don't specify it.

          Regards,
          Adrian

          • 2. Re: Multiple EJBs with same name in an EAR?
            McGee Newbie

            I don't have jboss.xml files, because I don't want the EJBS to have different names. I want a Web app that can test multiple versions of an ejb, and so I want to bundle multiple versions of the EJB, each in its own JAR, in an EAR along with the WAR for my testing Web app. I don't want to have to give each EJB a different name; I want to keep their JARS as they are.

            The spec says I can do this, but JBoss is not letting me.

            I've included the DDs below.

            Thanks,
            McGee

            -- application.xml for EAR --
            <?xml version="1.0" encoding="UTF-8"?>


            <display-name>Ear Test</display-name>

            Ejb1.jar


            Ejb2.jar




            -- ejb-jar.xml for Ejb1 --
            <?xml version="1.0"?>

            <ejb-jar>
            <enterprise-beans>
            <!-- EJB1 -->

            <ejb-name>Ejb</ejb-name>
            Ejb1
            Ejb1Home
            <ejb-class>Ejb1Bean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>

            </enterprise-beans>
            </ejb-jar>


            -- ejb-jar.xml for Ejb2 --
            <?xml version="1.0"?>

            <ejb-jar>
            <enterprise-beans>
            <!-- EJB2 -->

            <ejb-name>Ejb</ejb-name>
            Ejb2
            Ejb2Home
            <ejb-class>Ejb2Bean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>

            </enterprise-beans>
            </ejb-jar>

            • 3. Re: Multiple EJBs with same name in an EAR?
              Adrian Brock Master

              Re-read my previous post.
              The spec does not define the jndi bindings.

              -- jboss.xml for Ejb1 --
              <?xml version="1.0"?>

              <enterprise-beans>
              <!-- EJB1 -->

              <ejb-name>Ejb</ejb-name>
              <jndi-name>Ejb1</jndi-name>

              </enterprise-beans>


              -- jboss.xml for Ejb2 --
              <?xml version="1.0"?>

              <enterprise-beans>
              <!-- EJB2 -->

              <ejb-name>Ejb</ejb-name>
              <jndi-name>Ejb2</jndi-name>

              </enterprise-beans>


              Regards,
              adrian

              • 4. Re: Multiple EJBs with same name in an EAR?
                McGee Newbie

                Right, but I'm not trying to give two EJBs different names in my jboss.xml. I'm trying to have two EJBs with the same name, *but in different jar files*, in an EAR together, and to reference them with different names, e.g. in a Web app's DD using <ejb-link>s.

                The idea is that I want to be able to bundle multiple versions of an EJB inside an EAR for QA, and all I want to do is edit a Web app DD. I don't want to muck with the EJB DDs.

                The EJB spec clearly says this is possible, but JBoss isn't allowing it.

                I thank you for pointing out the jboss.xml workaround, but in this case it won't quite do it.

                Thanks again,
                McGee

                • 5. Re: Multiple EJBs with same name in an EAR?
                  Adrian Brock Master

                  Why is it a workaround?
                  The "deployer" is responsible for binding to jndi and
                  resolving conflicts.

                  Each ejb must have a unique <jndi-name>, it is a
                  global namespace.

                  If in app1 in you have
                  <ejb-name>User</ejb-name>

                  and in app2 you have
                  <ejb-name>User</ejb-name>

                  they will both get the jndi-name "User".

                  Instead you should have some strategy that binds the
                  ejbs to unique names across a server e.g.
                  <jndi-name>ejbs/app1/User</jndi-name>
                  <jndi-name>ejbs/app2/User</jndi-name>

                  You cannot do what you are trying to do anyway.
                  If you have different versions of the same class
                  in the same classloader space you are going to
                  hit a lot of problems.

                  Regards,
                  Adrian

                  • 6. Re: Multiple EJBs with same name in an EAR?
                    McGee Newbie

                    It's a workaround because the spec defines a method for resolving name problems within an EAR (via <ejb-link>), but JBoss doesn't appear to support that, though you can use jboss.xml to accomplish roughly, but not exactly, the same thing.

                    If I'm wrong, and JBoss does in fact allow mutiple EJBs with the same name to coexist in an EAR provided the referencing app uses the ejb.jar#ejbname syntax, with no need for jboss.xml or any other vendor-specific file, then I'm wrong. (That was, basically, my initial question.)

                    However, I take your point that in my case it's a moot issue, because I'm trying to have two versions of a class inside a ClassLoader namespace (=EAR?), and I'm going to have problems with that regardless. I *could* just rename one of the classes, but that's worse than just renaming an EJB.

                    Thank you Adrian,
                    McGee