
Since there is one stateful bean per client, using a stateful bean might impact the scalability of the application. The state maintained by the Stateful bean is lost when the server restarts or when the session times out. In our CourseManagement application, we can use a stateful bean to hold the Student data (student profile and the courses taken by him/her) after a student logs-in. Therefore, stateful beans can hold state data for the client between multiple method calls. There is a one-to-one mapping between the stateful session bean and the client. One stateful session bean serves requests for one client only.

Session beans come in three types, as follows. Any Plain Old Java Object ( POJO) can be annotated with the appropriate EJB-3-specific annotations to make it a session bean. In general, session beans are meant for containing methods used to execute the main business logic of enterprise applications. In this article, we will focus on session beans. Types of EJBĮJBs can be of following types as per the EJB 3 specifications: But before that, you need to understand some basic concepts of EJBs. In this article, we will create the same application using EJBs and deploy it in a Glassfish 4 server. (For more resources related to this topic, see here.) In addition to this, the container handles the life cycle of EJBs, including pooling of certain types of EJB objects so that more objects can be created when the load on the application increases. You can specify security constraints for calling EJB methods declaratively (using annotations), and you can also easily specify transaction boundaries (specify which method calls from a part of one transaction) using annotations. Even if you use EJBs on the same server as the web application, you may gain from a number of services that the EJB container provides to the applications through EJBs. But that is just one of the advantages of EJB. This is ideal in scenarios where you want components that process business logic to be distributed across different servers.

In this article by Ram Kulkarni, author of Java EE Development with Eclipse (e2), we will be using EJBs ( Enterprise Java Beans) to implement business logic.
