Types of EJB
EJB can be of the following types according to the EJB3 specification:
- Session bean:
- Stateful session bean
- Stateless session bean
- Singleton session bean
- Message-driven bean
We will discuss message-driven bean (MDB) in detail in a Chapter 10, Asynchronous Programming with JMS, when we learn about asynchronous processing of requests in the JEE application. In this chapter, we will focus on session beans.
Session beans
In general, session beans are meant to contain methods to execute the main business logic of the enterprise application. Any Plain Old Java Object (POJO) can be annotated with the appropriate EJB3-specific annotations to make it a session bean. Session beans come in three types.
Stateful session beans
One stateful session bean serves requests for one client only. There is one-to-one mapping between the stateful session bean and the client. Therefore, stateful beans can hold the state data for the client between multiple method calls. In our Course Management application, we...