I have read that @Stateful
bean (SFSB) should be never injected into @Stateless
bean (SLSB). But what is the correct way to achieve the following?
@Stateless
public class FirstEJB
{
@EJB
private SecondEJB second;
public void businessMethod()
{
second.businessMethod1();
second.businessMethod2();
}
}
There is some state that should be persisted between second.businessMethod1()
and second.businessMethod2()
, so SecondEJB
can't be stateless. There is also no easy way to merge businessMethod1()
and businessMethod2()
methods into single one, because SecondEJB
can have more than 2 business methods and they can be called in defferent combinations.
Actually I have tried to make SecondEJB
stateful and it seems to work, but it leads to memory leak. There is no SecondEJB
methods marked with @Remove
annotation, but I have tried @StatefulTimeout
with no luck: a lot of SecondEJB
instances created and not removed. Can someone explain why it leaks?