How does CDI delete a bean session?

The specification states that the CDI container removes the SFSB when the scope context is destroyed. How exactly does he remove the EJB? It doesn't seem to call 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 technically does what the specification says. The question is how to deal with the issue that the EJB container removes the instance? Thanks.

+6
source share
3 answers

As covener says, this is done using an implementation-specific EJB API that is not part of the standard EJB API.

As covener says, calling @Remove is NOT the right way to continue. The @Remove methods call the user code and tell the EJB container to remove the EJB. If you want to get a callback when uninstalling the EJB, use @PreDestroy.

+2
source share

I think the CDI container needs a hook in the EJB container so that it asks to "do what you would do if the @Remove method just finished." Looking at the EJB specification, EJB 2.1 had a mechanism for this in interfaces that you should have expanded.

For obvious reasons, a container calling an arbitrary annotated @Remove method for a side effect is not recommended.

+3
source share

The method with the @Remove annotation must be explicitly called by the client, then the container will call the method annotated with @PreDestroy implicitly, if it exists. After that, the bean instance will be ready for garbage collection.

This is the only life cycle method that the client can control; all other methods are controlled by the container.

-one
source share

All Articles