Java - EJB: Enterprise Java Bean (enterprise beans)


Enterprise beans are server-side J2EE components and run on the J2EE server in their EJB container which manages their execution. (Enterprise JavaBeans component model)

They handle the business logic of a J2EE application such as a web application. They contains the Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance.

An enterprise bean is a body of code with fields and methods to implement modules of business logic. You can think of an enterprise bean as a building block that can be used alone or with other enterprise beans to execute business logic on the J2EE server.

An enterprise bean:

  • receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage.
  • retrieves data from storage, processes it (if necessary), and sends it back to the client program.

in Enterprise JavaBeans terminology the installation process is called deployment.


  • Software Design - Scalability (Scale Up|Out). To accommodate a growing number of users, you can distribute an application’s components across multiple machines. Not only can the enterprise beans of an application run on different machines, but also their location will remain transparent to the clients.
  • Data - Transaction (Trans(versal?) actions) Enterprise beans support transactions, the mechanisms that manage the concurrent access of shared objects.
  • Multiple presentation layers. The application will have a variety of clients. With only a few lines of code, remote clients can easily locate enterprise beans. These clients can be thin, various, and numerous.

Type of Enterprise Beans

There are three kinds of enterprise beans:

  • Session: Performs a task for a client; optionally, may implement a web service
  • Message-driven: Acts as a listener for a particular messaging type, such as the JavaMessage Service API
  • Entity


In contrast with a session bean, an entity bean represents persistent data stored in one row of a database table. If the client terminates or if the server shuts down, the underlying services ensure that the entity bean data is saved.

One of the benefits of entity beans is that you do not have to write any SQL code or use the JDBC API directly to perform database access operations. With container-managed persistence, database access operations are handled by the the EJB container, and your enterprise bean implementation contains no JDBC code or SQL commands. However, if you override the default container-managed persistence for any reason, you will need to use the JDBC API.


A message-driven bean combines features of a session bean and a Java Message Service (“JMS”) message listener, allowing a business component to receive JMS messages asynchronously.

A message-driven bean is an enterprise bean that allows Java EE applications to process messages asynchronously.

This type of bean normally acts as a JMS message listener, which is similar to an event listener but receives JMS messages instead of events.

The messages can be sent by any Java EE component (an application client, another enterprise bean, or a web component) or by a JMS application or system that does not use Java EE technology.

Message-driven beans can process JMS messages or other kinds of messages.

The most visible difference between message-driven beans and session beans is that clients do not access message-driven beans through interfaces.

Message-driven beans do not have interfaces or no-interface views that define client access.

Unlike a session bean, a message-driven bean has only a bean class.

Naming Conventions

Item Syntax Example
Enterprise bean name nameBean AccountBean
Enterprise bean class nameBean AccountBean
Business interface name Account

EJBs and Other Application Components

Documentation / Reference

Powered by ComboStrap