4 Replies Latest reply on Oct 19, 2006 8:56 AM by wolfc

    why @Remote is preferred over @Local?

    metelka

      Hi,
      I have a @Remote & @Local interface

      @Remote
      @Local
      public interface IMyIfc { ... }
      

      SLSB that implements the interface
      @Stateless
      public class MyClass implements MyIfc { ... }
      

      and another SLSB where MyClass is injected
      @Stateless
      public class AnotherClass implements IAnotherIfc {
       @EJB
       IMyIfc myIfc;
      
       ...
      }
      


      I would expect that local proxy is injected into AnotherClass.myIfc, however EJB container injects remote proxy. My question is - what is the reason for preferring remote over local? I did not find anything about this issue in spec... I suggest changing the order, so that call-by-reference behaviour is preferred to call-by-value.

      Thanks,
      Petr

        • 1. Re: why @Remote is preferred over @Local?
          boby

          Hi,

          I made several tests and I find the same conclusion.
          So if anyone knows why the remote is used instead of the local, that will be nice ??

          My solution is to use @EJB inject like that :

          @EJB(mappedName = "masterServices/ResourcesSessionBean/local")
           private ResourcesSession resourcesSession;
          


          thanks,
          j. Bordeau

          • 2. Re: why @Remote is preferred over @Local?
            metelka

            I've created JIRA issue http://jira.jboss.com/jira/browse/EJBTHREE-663 quite a while ago... but nothing happened yet :(

            • 3. Re: why @Remote is preferred over @Local?
              erazero

              Hi

              I don't agree. Sure, this is a problem, but the solution is not try to optimize local over remote.

              Such as solution would create a undeterministic situation where sometimes calls get done local (with call-by-value and, for example, entity classes still attached) and sometimes calls get done remote (with call-by-reference, for example, entity classes detached). It would create hard-to-maintain, hard-to-debug and strange-error-behavior code.

              The solution is to either:
              * Deny/Warn deploy of code where the same java interface is used for both local and remote EJB3 interface.
              * Deny/Warn deploy of code that uses plain injection (without arguments) on a java interface that have multiple EJB3 interfaces.

              The design pattern we applied after discovering this behavior in JBoss is to Never use the same java interface for local and remote EJB3 interface.

              Regards
              F Persson

              • 4. Re: why @Remote is preferred over @Local?
                wolfc

                I've rejected this issue (as per spec 4.6.7 bullet 5.4).
                See also http://jira.jboss.com/jira/browse/EJBTHREE-751