Exercise 1.1: Introduction to the technologies

An enterprise bean is a set of JavaTM classes and interfaces that implement the Enterprise JavaBeansTM (EJB) specification. The EJB specification is a part of the JavaTM 2 Platform, Enterprise Edition (J2EE) specification. J2EE is a set of standardized Java technologies that extend the Java 2 Standardized Platform, Standard Edition (J2SE). Here are a few of the technologies that J2EE includes:

Applications that are written using the J2EE specifications are easily deployed on any server that provides J2EE support, such as IBMR's WebSphereR Application Server.

The most recent version of the EJB specification is 2.1. The workbench supports multiple versions of the EJB specification including 1.1, 2.0 and 2.1. You will see references to the different specification levels in the workbench. For instance, when creating a new container-managed (CMP) entity bean, you can select the CMP Version 1.x or 2.x, which correspond to the EJB versions 1.1 or 2.0/2.1, respectively.

For more information on the J2EE and EJB technologies, consult these Web sites:

Information on using these technologies can also be found in the following topics in the information center:

Enterprise JavaBeans

The EJB specification defines these things:

An enterprise application can be installed and run on an EJB server (also called an Enterprise Java Server), such as the one provided by WebSphereR Application Server. The server's task is to provide an EJB container where the enterprise beans run. An EJB server and container work together to provide these services:

Client applications do not access enterprise beans directly. Instead, interfaces are provided that list the methods of the enterprise bean that are available to the client. The container provides the implementation of the interfaces in the enterprise bean.

The EJB Container

The types of enterprise beans

There are three types of enterprise beans: session beans, entity beans, and message-driven beans. A typical EJB application consists of several entity beans, plus session or message-driven beans.

Entity beans are used to represent and interact with relational database tables. An entity bean typically represents a row in a database table, with the columns of the table corresponding to the fields in the bean. Data persistence refers to storing data permanently, in a database or other format. EJB containers can handle the persistence for an entity bean (container-managed persistence, or CMP); or, the entity bean can handle its own persistence (bean-managed persistence, or BMP).

Session beans are used to interact with entity beans. They usually provide the overall process or workflow for a client application. Session beans can be stateless (no data is saved) or stateful (some data is saved). Typically, an application client interacts with session beans, which in turn interact with entity beans.

Message-driven beans provide a communication vehicle for applications that want to access entity beans. They can be used in the same way that session beans are. The primary difference is how they are invoked. Session beans (and entity beans) are called synchronously, while message-driven beans are called asynchronously. A synchronous call to a session bean would be to invoke the session bean directly. An asynchronous call to a message-driven bean would be to send a message, for which the message-driven bean is listening. Java Messaging Service (JMS) is the underlying communications vehicle for message-driven beans.

More information on enterprise bean types can be found in the information center under EJB architecture.

The anatomy of an enterprise bean

An enterprise bean contains the following classes and interfaces:

Local and remote component interfaces

The local and remote component interfaces are used by client applications to access enterprise beans. These interfaces list the available business logic methods in an enterprise bean. An enterprise bean can have a remote interface, a local interface or both.

Performance is better when you access an enterprise bean using the local interface rather than the remote interface. Some of the reasons for the performance improvement include:

The local interface was added to the EJB 2.0 specification to improve performance. A recommended design practice is to wrap entity beans in a session facade, so that clients access the session bean remotely, but the session bean accesses the entity bean locally. This practice allows remote access from clients while providing better performance.

Local and remote home interfaces

The home interface of an entity bean is also used by client applications to access the enterprise bean, but the methods available through this interface are life cycle methods, including methods to find, create, and remove entity beans within the EJB container. Home interfaces can also be remote or local.

Enterprise bean classes

Enterprise bean classes contain the business logic of the enterprise application. Methods in the interfaces expose the corresponding methods in the bean class to client applications.

Primary key classes

A primary key is a unique ID that is associated with a specific entry in a database. For example, if you have a database of employees, each employee has a unique employee ID. Each instance of a primary key class corresponds to one of the unique IDs, and thus to a specific employee record in the database.

The anatomy of an enterprise application

The J2EE specification defines the files and directory structure of an enterprise application. In addition, it specifies the filetypes of .war, .ear and .jar, each type used for specific purposes.

An EAR file (Enterprise Archive) is the package type for an enterprise application. It contains WAR files and JAR files, as well as an application deployment descriptor (application.xml) that contains metadata about the enterprise application.

A WAR file (Web Archive) contains files for a Web application, such as images, HTML files, servlets and JSPs. It also contains metadata in the form of a Web deployment descriptor (web.xml).

JAR files (Java Archives) contain Java classes. In EJB applications, JAR files can contain EJB modules, or they can contain an EJB client application.

EJB modules contain the enterprise beans themselves, plus metadata including an EJB deployment descriptor (ejb-jar.xml). EJB modules deployed to WebSphere Application Server can also contain metadata describing IBM-specific extensions and binding information. An EJB client application contains the Java programs used to access an EJB application, plus a client deployment descriptor (application-client.xml).

Workbench projects and file types for EJB development
File type Meaning Application type Deployment descriptor
.ear Enterprise Archive enterprise application.xml
.war Web Archive Web web.xml
.jar Java Archive EJB
EJB client
ejb-jar.xml
application-client.xml

Using UML with Visual Editor

Visual Editor uses Unified Modeling Language (UML) to represent the structure and design of Java classes and interfaces, including EJB components, visually. It provides mechanisms for showing relationships between classes, as well as workflow. Using the UML tools within the workbench, you can visually edit Java classes and interfaces, or other EJB components. You can initiate the creation of an EJB component directly from a class diagram. The underlying code is generated and then visually rendered on the class diagram, ready to be edited. Changes made to a UML class diagram result in changes to the underlying code. Changes to the underlying code are reflected in the UML class diagram.

In the workbench, a UML class diagram is stored as a file with a .dnx extension.

UML 2 is a standard specification provided by the Object Management Group (OMG). The OMG Web site also provides an Introduction to UML.

The information center provides in-depth information on these topics:

Now you are ready to begin Exercise 1.2: Preparing the workspace.

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.