1 Reply Latest reply on Oct 14, 2001 3:21 PM by John Baker

    ejb's and inheritance

    Hugo Araujo Newbie

      Hi all,

      In my application I have this stateless bean:

      Remote interface:
      public interface AbstractReport extends EJBObject {
      public Report getReport() throws RemoteException;
      }

      Home interface:
      public interface AbstractReportHome extends EJBHome {
      public AbstractReport create() throws RemoteException, CreateException;
      }

      Bean:
      public class AbstractReportBean implements SessionBean {
      private SessionContext sessionContext;

      public void ejbCreate() {}
      public void ejbRemove() {}
      public void ejbActivate() {}
      public void ejbPassivate() {}

      public void setSessionContext(SessionContext sessionContext) {
      this.sessionContext = sessionContext;
      }

      public Report getReport() {
      return null;
      }
      }

      I also have this stateless bean wich extends the AbstractReportBean:

      Remote interface:
      public interface SalesReport extends AbstractReport {
      }

      Home interface:
      public interface SalesReportHome extends AbstractReportHome {
      }

      Bean:
      public class SalesReportBean
      extends AbstractReportBean implements SessionBean {
      private SessionContext sessionContext;

      public void ejbCreate() {}
      public void ejbRemove() {}
      public void ejbActivate() {}
      public void ejbPassivate() {}

      public void setSessionContext(SessionContext sessionContext) {
      this.sessionContext = sessionContext;
      }

      public Report getReport() {
      ...
      }
      }

      When I deploy in JBoss, I get this from the verifier:

      [Verifier]
      Bean : SalesReportBean
      Method : public abstract AbstractReport create()
      throws CreateException, RemoteException
      Section: 6.8
      Warning: The create method of a stateless session bean home interface must
      return the session bean's remote interface.

      [Verifier]
      Bean : SalesReportBean
      Method : public abstract AbstractReport create()
      throws CreateException, RemoteException
      Section: 6.10.6
      Warning: The return type for a create(...) method must be the session bean's
      remote interface type.


      I understand the warnings, but I want to use inheritance and can't think of
      another way of doing it.
      My application instantiates an AbstractReport and casts it to some Report like
      this:

      Context initial = new InitialContext();
      Object homeRef = initial.lookup("SalesReport");
      AbstractReportHome home = (AbstractReportHome) PortableRemoteObject.narrow(
      homeRef, Class.forName("SalesReportHome"));
      AbstractReport ar = home.create();
      ar.getReport(); // this will call getReport from the SalesReportBean

      Everything works fine, but am I missing something, or is this code following
      the especification?
      Any suggestion on using inheritance with ejb's is appreciated.


      Thanks in advance,
      Hugo Araujo

        • 1. Re: ejb's and inheritance
          John Baker Newbie

          Many products out there seem to overlook the fact you might have used inheritance when doing their object introspection. A common entity bean strategy is to extend the pass-by-value object to avoid having to rewrite the same get/set methods and fields etc but adding the entity bean stuff. Can you see if this works too as it should really as inheritance can be quite valid in a number of situations. I had hell when trying to use Together 5.0 with an existing EJB app for this very reason as it would rewrite all the remote interfaces, descriptors etc as empty and completely wreck everything!!