5 Replies Latest reply on Oct 16, 2006 5:38 PM by Bill Burke

    Local and Remote interfaces required in EJB3

    Hardy Ferentschik Novice

      Hi there,

      I am trying to get started with EJB3 and Seam and have a question regarding remote and local interfaces. It seems to define a stateful bean I have to do something along this lines:

      @Local
      public interface Foo
      {
      ...
      }

      @Stateful
      public class FooBean implements Foo
      {
      ...
      }

      I have to specify and interface which I annoate with @Local and then I need an actual bean implementation which I annoate with @Stateful. However, I thought that in EJB3 I don't need interfaces anymore. I hoped to be able to annoate a simple POJO. I recall reading somewhere that if eg I annotate a POJO as Stateful with no other annotation per default all public methods become part of the business interface. If I try to put the @Local annotation on FooBean itself removing the 'implements Foo' I get

      java.lang.RuntimeException: bean class has no local, webservice, or remote interfaces defined and does not implement at least one business interface

      Why are these interfaces still required. I could imagine something like this

      @Stateful
      public class FooBean implements Foo
      {
      @LocalMethod
      public void foo();

      @LocalMethod
      @RemoteMethod
      public void bar();
      }

      Why can I not annotate in a simple POJO which of my methods are exposed in the local/remote business interface. Of course I realize how much simpler EJB3 had become compared to EJB2, but without beeing able to annotate the buisness interface in the actual POJO it seems to be a half hearted apporach.

      Am I missing something?

      --Hardy


        • 1. Re: Local and Remote interfaces required in EJB3
          Andrew Rubinger Master

          The EJB3 spec eliminated the "Home" interfaces for obtaining a reference to a bean's proxy invoker.

          The reason that the Remote and Local interfaces are required is because clients of an EJB3 Bean obtain a reference to (and invoke methods on) this proxy object, generated by the container, which implements the Remote or Local interface as configured. The actual implementation instances reside on the server, and also implement the Local/Remote interfaces.

          S,
          ALR

          • 2. Re: Local and Remote interfaces required in EJB3
            Hardy Ferentschik Novice

            Sure, I understand that the client only gets a proxy to some interfaces and the bean implementation has of course to stay on the server. What I don't understand is why this interfaces could not be generated dynamically.

            For example using some imaginary annoations here:

            @Stateful
            @Local (interface="FooLocal")
            public class FooBean
            {
             @LocalMethod
             public void foo();
            
             @LocalMethod
             public void bar();
            }


            Wouldn't this be enough information for creating the client interface:

            public interface FooLocal
            {
             public void foo();
             public void bar();
            }


            Given you would stick to some sort of naming standard you could provide even default values for the names of the local and remote interfaces.

            Of course FooBean does not implement an interface now anymore, but invocations could be handled by some sort of dynamic proxy, right?

            --Hardy



            • 3. Re: Local and Remote interfaces required in EJB3
              Andrew Rubinger Master

              Sure...but wouldn't the generated interfaces have to be created at pre-compile time? And annotations provide metadata that's part of the compiled code...

              Of course FooBean does not implement an interface now anymore, but invocations could be handled by some sort of dynamic proxy, right?


              OK, but when you do your lookup to the proxy that doesn't implement an interface, how would you cast it or call methods on it?

              InitialContext ctx = new InitialContext(props);
              Object obj = ctx.lookup("jndiAddress");
              ((FooLocal)obj).foo(); // < You wouldn't be able to cast or invoke if the proxy doesn't implement an interface


              Sounds like you'd just like an XDoclet-esque step for generating Java source before compilation?

              S,
              ALR

              • 4. Re: Local and Remote interfaces required in EJB3
                Hardy Ferentschik Novice

                 


                Sounds like you'd just like an XDoclet-esque step for generating Java source before compilation?


                Yeah, sounds like it. I hoped that there would be no need for XDoclet anymore with EJB3, but it seems there actually is. I guess 'my imaginary' annoatations would in this case become XDoclet annotations which generate the interfaces pre-compliation.

                Nevertheless, it would just feel right to get rid of the local and remote interfaces.

                Thanks for your clarifications though.

                --Hardy

                • 5. Re: Local and Remote interfaces required in EJB3
                  Bill Burke Master

                   


                  Wouldn't this be enough information for creating the client interface:


                  Um, with Intellij or Eclipse, its really easy to extract an interface. So instead of typing @LocalMethod, just let your ide create an interface for you. Easier, less typing.