Java Reference
In-Depth Information
into EJB s. In addition, developing EJB s is still more complicated than developing
with lightweight technologies. In this section, we provide an overview of EJB 3 as
defined by the June 2005 public draft specification and describe the key improve-
ments as well as the remaining limitations and how to work around them.
10.1.1
Key improvements in EJB 3
EJB 3 has several key improvements that address deficiencies in EJB 2 . Let's look at
each one in turn.
EJBs are POJOs
To implement an EJB 2 bean, you must write classes and interfaces that are coupled
to the EJB container. For example, to implement an EJB 2 session bean you must
write a bean class that implements the SessionBean interface, a home interface
that extends EJBHome , and a component interface that extends either EJBObject or
EJBLocalObject . Because of the dependency on these interfaces, an EJB 2 bean can
only run inside the EJB container. It is anything but a POJO .
Implementing EJB 3 beans is much simpler because EJB 3 eliminates interfaces
such as EJBHome and SessionBean . EJB 3 beans are POJO s that do not extend or
implement those EJB -specific interfaces. For example, an EJB 3 session bean con-
sists of a plain old Java interface, which defines its public methods, and a POJO
bean class, which implements the interface. A message-driven bean is even sim-
pler and consists of only a POJO bean class.
An entity bean also consists of just the POJO bean class. Unlike EJB 2 it's a con-
crete class because you don't define abstract accessors for the container-managed
fields and relationship. The entity bean's fields or JavaBean-style properties are
mapped to the database using annotations or entries in the deployment descrip-
tor. An entity bean is instantiated using the new operator and persisted using the
EJB EntityManager , which is similar to a JDO PersistenceManager or Hibernate
Session and is described a bit later.
Because of these changes in EJB 3 , you have to write a lot less code when devel-
oping EJB 3 . As an added bonus, your code is a lot less dependent on the EJB con-
tainer. Later in this chapter you will see how POJO s developed earlier in this topic
can be deployed as EJB s.
Entity beans can run outside the EJB container
EJB 2 entity beans are inherently server-side components and can only run within
the EJB container. To test an entity bean, you have to wait for it to deploy in the EJB
container, which slows down the edit-compile-debug cycle. One drastic change in
the EJB 3 specification is that entity beans are no longer just a server-side technology.
 
 
 
 
Search WWH ::




Custom Search