Java Reference
In-Depth Information
The Enterprise JavaBean
Enterprise JavaBeans come in two fundamentally different flavors: the entity bean and the ses-
sion bean. Entity beans model a real-world object, a noun if you will. The entity bean is associ-
ated with persistent state held in a database. Simple examples are an employee, an
organization, a company, and any other object that might be represented in a database. Not
only does the entity bean represent the persistent data associated with the object, it also pro-
vides the functionality to make changes directly to the object.
Session beans on the other hand are not associated with a persistent state. They encompass a
process or task. This is where the business logic of your application exists. Session beans add
meaning to the changes that might be made on an entity bean. For example, reducing the num-
ber of a specific item in inventory and billing a customer are two tasks that by themselves do
not make much sense. However, they have a solid meaning when combined into the specific
context of selling the item to the customer.
The total transaction of billing a customer for a specific item, having it shipped, and maintain-
ing proper records on inventory makes use of many different objects. A customer bean and an
item bean are some entity beans that would be required to accomplish this task. A session bean
is required to perform all of the necessary steps and make all of the changes to the entity beans
to complete the process of selling this item to the customer.
There is resulting persistent data in the form of entity beans: for example, updated inventory, a
bill for the customer, and possibly a record of the credit card transaction, however the session
bean is inherently transient. The process begins, the steps are carried out, and then it is fin-
Interfaces and Classes
Now that you have some understanding of the difference between entity beans and session
beans, let's take a look at the objects and interfaces that make up an EJB.
Home Interface
The home interface for an EJB defines the lifecycle methods for the bean. It has methods for
creating, removing, and in the case of entity beans, searching beans. This is the first interaction
with an EJB that most clients have. The home interface extends the javax.ejb.EJBHome inter-
Remote Interface
The remote interface defines the business methods that can be performed on the bean. This is
the API that the bean presents the outside world for use. The remote interface extends the
javax.ejb.EJBObject interface.
Search WWH ::

Custom Search