Enterprise JavaBeans - (ejb 3.0) stateful session facade?
Hello,
(1) Would you consider stateful session facade (whose client is a servlet) a bad design?
(2) How to have a stateful session facade referenced in a servlet? I am using Sun Application Server Platform Edition 9.0 and trying to make an injection:
@EJB(name="ejb/KOGSessionFacade")
protected KOGSessionFacade sessionFacade;
but then I get this error in deploy-time: "A stateful session bean can not be injected into a servlet. Please refer to EJB 3.0 Persistence API Specification section #5.2 for further information."
Thanks.
[573 byte] By [
STFa] at [2007-11-26 23:17:08]

# 1
Using a Stateful Session facade from a Servlet is not necessarily a bad design. In some cases, you may want to do some cleanup work on completion of a transaction. Stateful Session beans provide a convenient way (By implementing SessionSynchronization interface) to do this.
In the servlet programming model, Servlets are not designed to be single threaded. So if you inject a StatefulSessionBean (SFSB) references then multiple threads could be possibly be invoking the SFSB concurrently. In this case, the EJBContainer (as required by the specification), will throw a well defined exception.
What you may want to do is to place this SFSB reference into you Servlet session.