1 Reply Latest reply on Dec 3, 2004 8:52 AM by frito

    STRANGE !!! Why call-by-reference when Serivice Bean call En

    rebeccawong33

      We are using BMP and have a service bean call a business method from an Entity bean. We find that the return value is by call-by-reference, that is what the service bean obtained is actally the same instrance stored in the entity bean.

      We are using commit option 'A' and remote interface (not local interface), why this situation will happen ? and how to disable it?

      sample code ... a method in the service bean ..

      /*********************/
      Context ctx = JBossContext.getContext();

      Object obj = ctx.lookup("ejb/ZDMDocumentsEB");
      com.dms.ejb.entity.ZDMDocumentsEntityRemoteHome homeInterface =
      (com.dms.ejb.entity.ZDMDocumentsEntityRemoteHome) javax.rmi.PortableRemoteObject.narrow(obj, com.dms.ejb.entity.ZDMDocumentsEntityRemoteHome.class);

      ZDMDocumentsEntityRemote remote = (ZDMDocumentsEntityRemote)
      homeInterface.findByPrimaryKey("804", "");

      // (1) !! an object reference is return by the entity bean class
      // This ojbject is a member of the entity bean class

      // doc is a helper class
      DocumentImpl doc = (DocumentImpl) remote.getEntityForView("");

      // (2) we try to set another value

      doc.setFiled("Set another value");

      // (3) get the data again

      DocumentImpl doc2 = (DocumentImpl) remote.getEntityForView("");
      // STRANGE !! We find that 'doc' and 'doc2' are the same object !!
      // and the modification on 'doc' is reflected on 'doc2' !!!!!

      System.out.println("doc2 == doc " + (doc == doc2));


      /*********************/

      Please advice..

      Thanks for your help!!

        • 1. Re: STRANGE !!! Why call-by-reference when Serivice Bean cal
          frito

          As default invocation (for a better performance) JBoss is using an invoker for bean-to-bean calls which is doing a call-by-reference.
          You can configure the invocation within the beans deployment descriptor (jboss.xml). If you are using the ByValueInvoker every call is done with marshalling/unmarshalling.
          Search the forum to find out how to use the ByValueInvoker. This was discussed many times.