1 Reply Latest reply on May 10, 2007 12:14 PM by Wolfgang Knauf

    Same JNDI name in multiple EAR files: mix up?

    Maik Hassel Newbie

      Hello, I have the same session bean library included in multiple EAR files - they perform the same functionality, just the persistence.xml for the underlying entity beans points to different databases.

      Code examples below!

      The web-middle tier (a jsf backing bean) now does a jndi lookup like this

      Context ctx = new InitialContext();
      DataManager) manager = (DataManager)ctx.lookup("someprefix/ejb/DataManagerBean");
      


      The data I get suggest that multiple calls of this code connect to different "versions" of the same session bean - the the data comes from different databases. It seems that the manager returned can be - rather random - from any one of the deployed ear files....

      The JNDI name is the same within any ear file, but can anyone suggest a way to restrict the lookups to the ear file without having to rename every bean???

      Thanks!


      Example:

      @Remote
      public interface DataManager {
       ...
      }
      
      
      @Stateless
      @RemoteBinding (jndiBinding="someprefix/ejb/DataManagerBean")
      public class DataManagerBean implements DataManager {
      
       @PersistenceContext(unitName="ONEOFMANYUNITS")
       private EntityManager em;
      
      // ...
      }





        • 1. Re: Same JNDI name in multiple EAR files: mix up?
          Wolfgang Knauf Master

          Hi !

          I hope I understand your problem, and I hope I can provide some help ;-).

          You have deployed the same bean in different ejb JARs, but your client lookup does not seem to find the bean which "belongs" to it ?
          I thought this should not be possible at all ;-).

          Well, you can control the JNDI names with jboss specific deployment descriptors.
          For each bean in an EJB jar you can specifiy to which JNDI name it should be bound:

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE jboss PUBLIC
           "-//JBoss//DTD JBOSS 4.2//EN"
           "http://www.jboss.org/j2ee/dtd/jboss_4_2.dtd">
          <jboss>
           <enterprise-beans>
           <session>
           <ejb-name>DataManagerBean</ejb-name>
           <jndi-name>DataManager1</jndi-name>
           <local-jndi-name>DataManager1Local</local-jndi-name>
           </session>
           </enterprise-beans>
          </jboss>


          This will redefine the global JNDI name of the bean (defaults to EARName/EJBName/local).

          On the client side, an ENC entry will be defined in jboss-web.xml and references the new JNDI name:

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE jboss-web PUBLIC
           "-//JBoss//DTD Web Application 4.2//EN"
           "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
          <jboss-web>
           <context-root>...</context-root>
           <ejb-ref>
           <ejb-ref-name>ejb/DataManagerBean</ejb-ref-name>
           <jndi-name>DataManager1</jndi-name>
           </ejb-ref>
          </jboss-web>


          Hope this helps !

          Wolfgang