Programming Tutorials

Types of EJB

By: aathishankaran in EJB Tutorials on 2007-02-20  

There are three types of Enterprise Java Beans namely:

  • Session Beans
  • Entity Beans
  • Message driven beans
  1. Session Beans

    Session Beans are the most commonly used type of EJBs. They are lightweight and are designed to provide business logic to the client application. Session Beans can be of two types: stateless and stateful. Stateless session beans are used when the client doesn't need to maintain any state information between requests, while stateful session beans are used when the client needs to maintain state information between requests.

    Session beans are divided into two types:

    a) Stateless Session Bean: Stateless Session Bean is intended to be simple and "light weight" components. The client, thereby making the server highly scalable, if required, maintains any state. Since no state is maintained in this bean type, stateless session beans are not tied to any specific client, hence any available instance of a stateless session bean can be used to service a client.

    b) State full Session Bean: State full Session Bean provides easy and transparent state management on the server side. Because state is maintained in this bean type, the application server manages client/bean pairs. State full session beans can access persistent resources on behalf of the client, but unlike entity beans, they do not actually represent the data.

  2. Entity Beans:

    Entity Beans represent persistent data and are used to interact with the database. They are responsible for storing and retrieving data from the database. There are two types of Entity Beans: Container Managed Persistence (CMP) and Bean Managed Persistence (BMP). In CMP, the container is responsible for all database interactions, while in BMP, the developer has to write the code to interact with the database.

  3. Message-Driven Beans:

    Message-Driven Beans (MDBs) are used for asynchronous communication between distributed components. They are used to listen to messages from a message queue or a topic and execute the required logic. MDBs are often used in distributed systems, where different components need to communicate with each other asynchronously.

Each type of EJB has its own specific purpose and benefits, and can be used based on the requirements of the application.

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in EJB )

Latest Articles (in EJB)