The Bean-Container Contract
The environment that surrounds the beans on the EJB server is often called the container. The container is more a concept than a physical construct. It acts as an intermediary between the bean and the EJB server. It manages the EJB objects and EJB homes and helps these constructs to manage bean resources and provide services such as transactions, security, concurrency, and naming at runtime. The distinction between the container and the server is not clearly defined, but the EJB specification defines the component model in terms of the container’s responsibilities, so we will follow that convention here.
Enterprise bean components interact with
the EJB container through a well-defined component model. The
EntityBean,
SessionBean
, and
MessageDrivenBean
interfaces provide callback methods
that notify the bean class of life-cycle events. At runtime, the
container invokes these methods on the bean instance when relevant
events occur. For example, when the container is about to write an
entity bean instance’s state to the database, it
first calls the bean instance’s ejbStore( )
method. This call gives the bean
instance an opportunity to do cleanup on its state before
it’s written to the database. The
ejbLoad( ) method is
called just after the bean’s fields are populated
from the database, providing the bean developer with an opportunity
to manage the bean’s state before the first business
method is called.[9] Other callback methods can be used by the ...