Session Bean

Session beans are the only EJB components that are invoked directly by clients.

Another word, entity bean or Message-Driven Bean could not be invoked directly by clients.

Then who could invoke Entity Bean or MDB?


  • Stateless: This type of bean does not maintain any conversational state on behalf of a client application.
  • Stateful: This type of bean maintains state, and a particular instance of the bean is associated with a specific client request. Stateful beans can be seen as extensions to client programs that are running on the server.
After Java EE5, a stateless session bean class is any standard Java class that has a class-level annotation of @Stateless. Although you don't have to have @Stateless annotation, you could use deployment descriptors, and if dd is used, it could override annotation.

Stateless Session Bean Callback Methods:
  • PostConstruct
  • PreDestroy
Stateful Session Bean Callback Methods: 
  • PostConstruct: Denoted with the @PostConstruct annotation. Any method in the bean class can be marked with this annotation.
  • PreDestroy: Denoted with the @PreDestroy annotation.
  • PreActivate: Denoted with the @PreActivate annotation.
  • PrePassivate: Denoted with the @PrePassivate annotation.