Creating a stateful session bean

In order to illustrate the creation of a stateful EJB, we will use a bean to maintain a list of names. A name will be entered in the index.jsp page and passed to a servlet. The servlet will add the name to the stateful bean. Unique to the stateful EJB is the process of passivation. When a stateful bean is experiencing a period of inactivity, the EJB container may decide to remove it from memory temporarily. This process is called passivation. Most of the state of the EJB is saved automatically except for transient fields. When the EJB is restored, the stateless EJB has its original content except for the transient fields.

Getting ready

Creating a stateful session bean requires:

  1. Annotating a class with the @Stateful ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.