Overview: Enterprise Java Beans

As with all controls in WebLogic Workshop, the EJB control is designed to hide most of the details of the resource the control represents. Therefore, you should be able to create an EJB control without knowing most of the information in this topic. This information is provided as background.

If you want to learn more about J2EE and EJBs, please consult the WebLogic Server documentation, java.sun.com or the J2EE programming book of your choice.

# What Is an EJB?

An Enterprise Java Bean is a server-side component that encapsulates the business logic of an application. The business logic is the code that fulfills the purpose of the application, as opposed to code that provides infrastructure and plumbing for the application. In an inventory control application, for example, the EJBs might implement the business logic in methods called checkInventoryLevel and orderProduct. By invoking these methods, remote clients can access the inventory services provided by the application.

EJBs always execute within an EJB container, which provides system services to EJBs. These services include transaction management, persistence, pooling, clustering and other infrastructure.

# EJB Interfaces

EJB expose two types of interfaces, called the home interface and the business interface (prior to EJB 2.0, the business interface was generally referred to as the bean's remote interface).

Clients obtain an instance of the EJB with which to communicate by using the home interface. The methods in the home interface are limited to those that create or find EJB instances.

Once a client has an EJB instance, it invokes methods of the EJB’s business interface to do real work. The business interface directly accesses the business logic encapsulated in the EJB.

To create an EJB control to represent an EJB, you must know the names of the home and business interfaces. The name for the home interface is typically of the form com.mycompany.MyBeanNameHome and the business interface is typically of the form com.mycompany.MyBeanName.

# Types of EJBs

In J2EE 1.3 there are three types of EJBs: Session Beans, Entity Beans and Message-Driven Beans. Each of these types is described briefly in the following sections.

The EJB control provides web services the ability to act as a client for Session and Entity EJBs. Requests can be sent indirectly to Message-Driven bean using the JMS control, thus the EJB control does not support Mesage-Driven Beans.

## Session EJBs

A session EJB represents a single client inside the application server. A client of the application accesses the application by invoking the session bean's methods. The session bean shields the client from complexity by executing business tasks inside the server, perhaps by invoking other EJBs.

A session bean is not shared: it may have just one client. Like an interactive session, a session bean is not persistent. When the client terminates, its session bean appears to terminate and is no longer associated with the client.

## Entity EJBs

An Entity EJB represents a business object in a persistent storage mechanism. Some examples of business objects are customers, orders, and products. The persistent storage mechanism is a relational database. Typically, each entity bean has an underlying table in a relational database, and each instance of the bean corresponds to a row in that table.

Entity beans differ from session beans in several ways. Entity beans are persistent, allow shared access, have primary keys, and may participate in relationships with other entity beans.

## Message-Driven EJBs

A Message-Driven EJB is an enterprise bean that is able to listen for JMS (Java Message Service) messages. The messages may be sent by any JMS-compliant component or application. Message-Driven EJBs provide a mechanism for J2EE applications to participate in relationships with message-based legacy applications.

Related Topics

EJB Control: Using Enterprise Java Beans from a Web Service

Controls: Using Resources from a Web Service