5 Replies Latest reply on Jul 27, 2006 10:03 AM by gus888

    Session bean inheritance

    gus888

      Hi All,

      I want to whether it is possible to use inheritance in session beans as follows:

      public interface BaseInterface {
       public boolean isNew();
      
       public void destroy();
      }
      
      @Local
      public interface ProjectEditor extends BaseInterface {
       ...
       //other business logic
      }
      
      public class BaseBean implements BaseInterface {
      
       @In(create=true)
       private EntityManager entityManager;
      
       @TransactionAttribute(NOT_SUPPORTED)
       public boolean isNew() {
       return isNew;
       }
      
       @Destroy @Remove
       public void destroy() {}
      
      }
      
      
      
      @Name("projectEditor")
      @Stateful
      public class ProjectEditorBean extends BaseBean implements ProjectEditor {
       ...
       //other business logic
      }

      Thank you in advance for any guidance!
      Gus

        • 1. Re: Session bean inheritance
          bfo81

          I think so. Have a look at the "avoiding DRY" thread ;).

          • 2. Re: Session bean inheritance
            gus888

            Thank you VERY MUCH, bfo81. The "avoiding DRY" is great topic.

            • 3. Re: Session bean inheritance
              bfo81

              Yes, it is :). Just one more thing:

              There are annotations that can be used in abstract superclasses (like @PersistenceContext, @In, @Out, @Logger, @Begin, @End, @Remove, @Destroy...) and there are some that must be applied to the concrete subclasses (@Stateful, @Stateless, @Name (of course *g*), @Conversational, @Scope, ...).

              I'm not 100% sure, but I think that you can annotate the methods and properties of a superclass but not the class itself. But as I said, I'm not absolutely sure about that. Maybe someone with a deeper insight into the things going on can tell as a simple rule regarding this ;).

              • 4. Re: Session bean inheritance
                gavin.king

                Any annotation on a superclass _member_ should be inherited to the subclass. Annotations on the superclass _type_ are not, in general.

                • 5. Re: Session bean inheritance
                  gus888

                  BFO81, thank you so much for the excellent detailed explanation.

                  Gavin, thank you so much for your OFFICIAL confirmation.