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.

Mahesh.Kannana at 2007-7-10 14:18:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
EJB is on Business Tier.Servlet is on Presentation Tier.Neither servlet or httpsession objects should have any direct references to EJB on the tier below. Check out Business Delegate design pattern to see how to coordinate communication between tiers.
GhostRadioTwoa at 2007-7-10 14:18:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
I wrote "servlet", but in fact I meant business delegate POJO accessible from a servlet.I think it doesn't make much difference.
STFa at 2007-7-10 14:18:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
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
GhostRadioTwoa at 2007-7-10 14:18:17 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...