1 Reply Latest reply on Aug 2, 2004 9:08 AM by jamesstrachan

    deploying beans with the same name

    Jonathon Roberts Newbie

      I have an application using Session and Entity beans.

      Now we have a second customer. I want to deploy the same application, but use a seperate database for each customer.

      How can I do this on the same server without getting a bunch of InstanceAlreadyExistsException?

      Do I have to rename each bean and change each reference in the code? Is there some sort of higher up referance I can access or set?


      Jon Roberts

        • 1. Re: deploying beans with the same name
          jamesstrachan Newbie


          You obviously have to deploy the beans with different names and JNDI names to avoid conflict. Providing that you use a consistent naming structure such as :-


          with, for the second customer,

          then it is relatively easy to edit the DeploymentDescriptor for each customer with a global search and replace. Within the J2EE world, mapping to the new customer can be done by changing references in jboss.xml :-


          The other half of the problem is to produce the required JNDI name for access to different customers from a client outside the EJB world. I normally use a name factory for this, and enclose a partial code sample below :-

          public class myJndiNameFactory {
          public static final int BEAN1 = 1;
          public static final int BEAN2 = 2;
          private static String customerJndiRoot;
           public myJndiNameFactory() {
           customerJndiRoot = System.getProperty("customer.root");
           public String getJndiName( int logicalName ) throws InvalidLogicalNameException {
           switch ( logicalName ) {
           case BEAN1: {
           return "ejb/" + customerJndiRoot + "/bean1";
           // switch statements follow for each logical name.
          None of this is a "magic wand", and does require consistency in the use of naming conventions and alterations to your existing codebase.
          But it's about the best that can be done.