ejb's and inheritance
haraujo Oct 11, 2001 5:49 PMHi 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