Java Reference
In-Depth Information
Chapter 20: Enterprise JavaBeans
In This Chapter
This chapter gives a brief overview of Enterprise JavaBeans (EJBs). The features and purposes of three
types of EJBs are discussed. The fundamentals of transaction and persistence management are
reviewed. After reading this chapter, you should have a good understanding of Enterprise JavaBeans
(EJBs) and of the ways they interact with databases.
Enterprise JavaBeans Overv iew
The Enterprise JavaBeans Specification defines EJBs as follows: "Enterprise JavaBeans is an
architecture for component-based distributed computing. EJBs are components of the distributed
transaction-oriented enterprise applications." In a nutshell, EJBs are server-side components that
encapsulate the business logic of an application. The business logic is the code that fulfills the purpose
of the application. For example, in an online shopping application, the EJBs might implement the
business logic in methods called searchCatalog and checkOut . By invoking these methods, remote
clients can access the online shopping services the application provides.
An EJB typically communicates with Enterprise Information Systems (EIS) such as databases and
legacy systems and other EJBs. At the same time, different types of clients access EJBs requesting
services. The clients can be other EJBs, Web applications, servlets, or application clients.
At runtime, an EJB resides in an EJB container. An EJB container provides the deployment and runtime
environment for EJBs, including services such as security, transaction, deployment, concurrency
management, and instance life-cycle management. The process of installing an EJB in an EJB
container is called EJB deployment . EJB containers are typically part of an application server. EJBs by
nature are portable components; therefore, the application assembler can build new applications from
existing beans with minimum effort. These applications can run on any J2EE-compliant application
servers.
EJBs are designed to simplify the development of large, distributed applications. Because the EJB
container provides system-level services to enterprise beans, the bean developer can concentrate on
solving business problems. The EJB container, not the bean developer, is responsible for system-level
services such as transaction management and security authorization. Furthermore, since the
application's business logic is contained in EJBs instead of in clients, client developers can focus on the
presentation of the client. The client developer does not have to code the routines that implement
business rules or access databases. As a result, clients are thinner. This is particularly beneficial for
clients that run on small devices such as cell phones or PDAs.
EJBs are especially suitable for applications that have the following requirements and characteristics:
 
Scalablability. To accommodate a growing number of users, one may need to distribute an
application's components across multiple machines. Not only can the EJBs of an application run on
different machines, but their location remains transparent to clients.
 
Transactions-oriented. EJBs support transactions through container services, the mechanisms
that manage the concurrent access of shared objects and ensure data integrity.
 
Multiple types of clients. With just a few lines of code, remote clients can easily locate enterprise
beans. These clients can be thin, various, and numerous.
The EJB 2.0 Specification specifies the three following types of EJBs:
 
Session beans
 
Entity beans
 
Message-driven beans
The features, as well as the appropriate uses of each type of EJB, are discussed in more details in the
following sections.
Session Beans
Search WWH ::




Custom Search