First page Back Continue Last page Graphics
...Session Beans
Bean instance can react to removal
- SessionBean defines ejbRemove( ):
- Container calls it before removing bean instance
- Last EJB method called before bean is destroyed
How to use ejbRemove( )?
- To release instance resources (JDBC connections, etc.)
To abort removal:
- Throw EJBException from ejbRemove( )
- May contain an Exception indicating proximate cause
Notes:
In the bean class instance, the container calls the ejbRemove( ) method from the SessionBean interface just before releasing the instance. Thus it is the last EJB method called in the life of the bean instance. ejbRemove( ) would typically release the same resources acquired in the ejbCreate( ) method, and may look very much like. the ejbPassivate( ) method.
Note that while create( ) / ejbCreate( ) can be overloaded, there is only one remove( ) / ejbRemove( ) pair. Like a C++ destructor or Java's finalize( ) method, these are not overloaded.
The bean instance can abort the removal by throwing an EJBException containing a nested exception. This comes back to the client as a RemoteException thrown on the remove( ) call.
For example, on the next page is the LegacyAppSessionBean class again, showing its ejbRemove( ) method. Note the similarity to ejbPassivate().