Persistance of EJB Beans

EJB containers can manage both transient EJB beans and persistent EJB beans.

Container-managed persistance

  • EJB container is responsible for saving the Bean's state
  • the fields (instance variables) that hold the internal state and thus have to be saved/restored are specified in the deployment descriptor
  • Java serialization mechanism us used to store bean's instance variables of structured (but serializable) types
  • datasource (i.e. the parameters to connect to a database where the bean's status has to be saved) must be specified in deployment descriptor
  • bean's implementation is independant of the data source - it's code contains no commands accessing persistant storage (database) directly

Note: Persistent or entity beans encapsulate in their object reference a unique ID (the serialized key) that points to their state, i.e. a key of the bean's state record in the persistant storage.

Bean-managed persistance

  • in this case, the Entity Bean is directly responsible for saving and restoring its own state
  • commands for saving and restoring bean's state are part of bean's code
  • not recommended except in cases where a special control of the presistant state is needed
First Previous Next

Slide: 16