2 Replies Latest reply on Mar 7, 2006 2:19 PM by fcheng

    ejb3.0 cannot have the same interface being shared by multip

    fcheng

      I have multiple stateless beans share the same interface and I am switching to ejb3.0. But resue the interface failed the ejb lookup for ejb3.0. Any solution to resolve this problem in ejb3.0?

        • 1. Re: ejb3.0 cannot have the same interface being shared by mu
          heinrich

          any code?

          • 2. Re: ejb3.0 cannot have the same interface being shared by mu
            fcheng

            The old code is:

            DbAccessFactory.java:
            public class DbAccessFactory {
            public DbAccessHome getHome(Hashtable p, boolean proxy) throws NamingException {
            DbAccessHome dbAccessHome = null;
            try {
            InitialContext ctx = new InitialContext(p);
            if (proxy) {
            dbAccessHome = (DbAccessHome)PortableRemoteObject.narrow(ctx.lookup("ejb/DbAccessProxy"),DbAccessHome.class);
            }
            else {
            dbAccessHome = (DbAccessHome) PortableRemoteObject.narrow(ctx.lookup("ejb/DbAccess"), DbAccessHome.class);
            }
            }
            finally {...}
            return dbAccessHome;
            }
            }

            DbAccessBean.java:
            public class DbAccessBean implements SessionBean, DbAccess {...}

            DbAccessProxyBean.java:
            public class DbAccessProxyBean implements SessionBean, DbAccess {
            private DbAccessHome siteAHome;
            private DbAccessHome siteBHome;

            public void ejbCreate()throws javax.ejb.CreateException {
            try {
            InitialContext ctx = new InitialContext();
            siteAHome = (DbAccessHome) PortableRemoteObject.narrow(ctx.lookup("ejb/SiteA"), DbAccessHome.class);
            siteBHome = (DbAccessHome) PortableRemoteObject.narrow(ctx.lookup("ejb/SiteB"), DbAccessHome.class);
            }
            catch (NamingException e) {...}
            finally {...}
            }

            public long access() throws RemoteException {
            DbAccess dbAccess = null;
            if(isSiteA) {
            dbAccess = siteAHome.create();
            }
            else {
            dbAccess = siteBHome.create();
            }
            dbAccess.getData();
            }
            ...
            }

            I tried to convert the code to:

            public DbAccess getHome(Hashtable p, boolean proxy) throws NamingException {
            DbAccess dbAccess = null;
            InitialContext ctx = new InitialContext(p);
            try {
            if (proxy) {
            dbAccess = (dbAccess) ctx.lookup(DbAccess.class.getName());
            }
            else {
            dbAccess =(dbAccess) ctx.lookup(DbAccess.class.getName());
            }
            finally {...}
            return dbAccess;
            }

            But how to differentiate the proxy beans if the lookup class is the same?