How does CDI remove stateful session bean?
cdi, ejb-3.1
Solution
As covener says this is done using an implementation specific EJB API, that isn't part of the EJB standard API.
As covener says, calling @Remove is NOT the right way to proceed. @Remove methods are called by users code, and tell the EJB container to remove the EJB. If you want a callback when the EJB is removed, use @PreDestroy.
Problem
The spec says that CDI container removes a SFSB when the scope's context is about to be destroyed. How does it exactly remove the EJB? It does not seem to be calling the method annotated with @Remove. ``` @Stateful public class CustomerDAOImpl implements CustomerDAO { @PreDestroy public void onDestroy() { //This is getting called as expected } @Remove public void deleteMyBean() { //This is not getting called! } } ``` So, CDI is technically doing what the spec says. The question is how is it managing to ask the EJB container to remove the instance? Thanks.