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???



      public interface DataManager {
      @RemoteBinding (jndiBinding="someprefix/ejb/DataManagerBean")
      public class DataManagerBean implements DataManager {
       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"

          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"

          Hope this helps !