Database Reference
In-Depth Information
EJB components have four parts:
1. An implementation class that contains the business logic.
2. Home interfaces that present the EJB methods to the outside world.
3. Remote interfaces that present the EJB methods to the outside world.
4. A deployment descriptor: An XML file that is used to configure the EJB component being
deployed in a J2EE server. For example, a deployment descriptor can define the security
properties or transaction properties of EJB methods.
EJBs are container-managed components, that is, the container manages their life cycle and, based
on the configuration specified in the deployment descriptor, interacts on behalf of the EJBs with
various J2EE services.
The success of EJBs is based on a set of key concepts. First, EJBs are deployed within a con-
tainer hosted by an application server, rather than deploying directly onto the application server. A
container provides the environment for execution of EJBs, management of their life cycle, and pro-
visioning of additional services. Second, EJBs take an approach based on proxy pattern rather than
a monolithic component, which effectively separates out the component into client objects and
remote objects. While the EJB user only sees the client object represented by the EJB interfaces,
the remote object is free to change in terms of implementation details like location on the network
and underlying transport mechanism. Third, EJBs use the concept of deployment descriptors that
decouples the development from the deployment aspects.
There are three types of EJBs:
1. Entity Beans : Entity beans are EJBs designed specifically to represent data in a persistent
store, which is typically a database. They encapsulate persistent data in a data store, which
is typically a row or record of data in a database table. Apart from the built-in database
access and synchronization capabilities, entity beans automatically provide the ability to
share both state and behavior across multiple clients concurrently, disaster recovery facili-
ties, and so on.
An entity bean consists of a Home interface, a Remote interface, an implementation
class, and a primary key class. The Home interface defines create, finder, remove, and home
methods. The remote interface defines business methods. It also has a primary key class that
contains methods for operating on the primary key for a single or a compounded database
table. The implementation class implements all of the life-cycle, finder, select, and business
methods. Like all EJBs, entity beans also make use of the deployment descriptor to hold
additional information pertaining to the component including transaction settings on busi-
ness methods, relationships with other entity beans, and persistent filed settings.
2. Session Beans : Session beans are the most popular of the EJBs and are used primarily to
manage transactions or client sessions. In an enterprise application, they are often used as
the main controller connecting servlets or JSPs to entity beans or other components. Apart
from the built-in transaction management and state management capabilities, EJB container
also provides additional services such as automated resource management, concurrency, and
securit y.
These are used mainly for transient activities. They are nonpersistent and often encapsu-
late bulk of the business logic. While stateful session beans retain client state between succes-
sive interactions with the client, stateless session beans do not do so. In the case of a stateless
session bean, each successive invocation of the bean is treated as an independent activity.
Search WWH ::




Custom Search