Since a bean can be using some resources such as socket or database cursor and a container can not retain such resources, EJB defines two callback methods on the object to inform that it is about to be passivated (ejbPassivate()) or activated (ejbActivate()). The implementation of bean is responsible for releasing and obtaining those external resources within these methods. |
Container invokes ejbPassivate() method on the bean and then serialize all its fields by using Java serialization. |
Container invokes a setSessionContext() method on the EJB session bean to give the a handle to its context where a bean can access its context maintained by the container. Container uses a SessionContext for session beans. |