Introduction to Enterprise Java Beans for Freshers

Enterprise Java Beans is a type of architecture for component-based distributed technology. It is arguably the most important aspect of that architecture. Accordingly all other components work alongside with the enterprise beans to make all bean related applications.

 

Enterprise beans are components that are section of a distributed, transaction-oriented enterprise system. They have the following features:

 

a. They have a container environment to supply life-cycle services for applications.

b. Manipulation of the enterprise’s data using business logic.

c. By editing an XML-based deployment descriptor they can be customized at deployment time.

d. Transaction management such as system-level services and security are described separately from the bean.

e. A client can’t access an enterprise bean directly; the container environment allows access for the client.

f. The EB is designed to be portable and reliable across EJB servers provided by different vendors.

 

Behalf of EJB 2.0 Specification, there are three different types of enterprise beans:

 

A) Entity bean

B) Session bean

C) Message-driven bean

 

Entity Bean

An entity bean typically represents a row in a RD (Relational Database). Just as there is a row in a database table for each record, there is possibly a single entity bean instance created for each row. For example, if the admin have an Order table that follows all the orders placed by users, user would have one entity bean instance for each Order, although there is some flexibility for how the programmer implements this exactly.

 

Session Bean

This type of bean typically represents business-level logic that an application needs to execute or deploy. It usually combines several processing steps that must be completed as an atomic unit within the module. It means that all the processing should be finished or none of them should. For example, if user had a method called complete Order that needed to confirm and charge a customer’s credit card payment, submit the order, and then send an e-mail message to the shipping department to start retrieving the order; these processing may be collaborated and put into a session bean method itself. If the order could not be submitted, the customer should not be charged or the payment should not taken place. All these actions can be combined into a single session bean method call.

 

Message-Driven Bean

This type of beans is new to the EJB family starting with version 2.0. Message-Driven Bean is used to handle Java Message Service (JMS) messages asynchronously. It is very different from the other types of EJBs in two key ways. For one, the message-driven bean is not exposed directly to users. A message-driven bean listens for messages that are sent using JMS and evaluates those messages anonymously.