A session bean is an EJB that provides a service to a particular user session.
Session beans model processes.
Session beans don't survive container crashes. Relative to entity
beans, session beans are short-lived. A session bean can be one of two types:
Stateless - The bean saves no information between sessions.
These EJBs are useful for simple interactions between client and application
service, interactions that are complete in a single method invocation. A
common example is an EJB that processes orders. Each order can be processed
by an invocation of one method, such as processOrder(). All the
information needed for processing is contained in the method parameters.
Stateful - The bean saves information between sessions.
These EJBs are useful for business processes that require an interaction
between client and application service that lasts longer than a single method
invocation and requires maintenance of state about the interaction. A common
example is an on-line shopping cart. The end user, through the client program,
can order a number of items. The stateful session bean managing the interaction
must accumulate orders until the end user is ready to review the accumulated
orders, approve or reject them, and initiate processing. The stateful EJB
would have to hold the unprocessed orders while allowing end users to add more.