tags:

views:

225

answers:

1

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.

A: 

Hi,

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 F D Garcia