Can I call a Stateful Session Bean through a Stateless Session Bean? Is the client of the SFSB then automatically the client of the SLSB for state preservation purposes? The problem is that because of the design being set in stone, I am not easily allowed to call the SFSB directly.
Asked
Active
Viewed 2,037 times
1
-
If you want, see http://stackoverflow.com/questions/1473939/ejb-lookup-failing-with-namingexception/1496306#1496306 – Arthur Ronald Oct 01 '09 at 13:49
1 Answers
3
If you call a Statful session beans inside a business method, no problem.
@Stateless
@EJB(name="ejb/myStateful", beanInterface=MyStateful.class)
public class MySteteless implements MyStatelssBusinessInterface {
@Resource
private SessionContext context;
public void businessMethod() {
MyStateful stateful = (MyStateful) context.lookup("ejb/myStateful");
stateful.doSomething();
}
}
Correct: if you call context.lookup, YOU HAVE TO DECLARE MyStateful through @EJB annotation as shown abobe.
Advice: it does not makes sense call a stateful inside a stateless.
regards,

Arthur Ronald
- 33,349
- 20
- 110
- 136