1 Reply Latest reply on May 13, 2007 1:18 PM by jaikiran pai

    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?
          jaikiran pai Master

           

          but can anyone suggest a way to restrict the lookups to the ear file without having to rename every bean???


          How about adding a jboss.xml file to each of the application and specifying a different jndi name for the beans in each application? Something like:

          in jboss.xml of app1:

          <ejb-name>DataManagerBean</ejb-name>
          <jndi-name>app1/ejb/DataManagerBean</jndi-name>
          


          in jboss.xml of app2:

          <ejb-name>DataManagerBean</ejb-name>
          <jndi-name>app2/ejb/DataManagerBean</jndi-name>
          


          Ofcourse, you would have to change the code where the lookup of the bean is happening.

          String appName = getAppName();//implement some logic to pickup the appName from a properties file or the env-entry
          Context ctx = new InitialContext();
          DataManager) manager = (DataManager)ctx.lookup(appName + "/ejb/DataManagerBean");