18.104.22.168. Enterprise JavaBeans: Distributed business components
Enterprise JavaBeans (EJB ) do for server-side enterprise programs what Java beans do
for client-side GUIs. EJB is a component model for units of business logic and business
data. Programming models that take business logic out of the client and put it on a server
or in a middle tier have many advantages in enterprise applications. However, the task of
writing this middleware has always been complicated by the fact that business logic must
be mixed in with code for handling transactions, security, networking, and so on.
The EJB model attempts to separate high-level business logic from low-level housekeeping
chores. And in the process, it attempts to leave the former to you, the enterprise developer,
while the latter is delegated to the EJB server. A component in the EJB model is an object
that implements business logic or represents business data. The difference between an
enterprise bean and a run-of-the-mill RMI remote object or nonremote Java bean is that
EJB components run within an EJB container, which in turn runs within an EJB server.
The container and server provide features such as transaction management, resource
pooling, lifecycle management, security, name services, distribution services, and so on.
With all these services provided by the container and server, enterprise beans (and
enterprise bean programmers) are free to focus purely on business logic.
The EJB specification is a document that specifies the contracts to be maintained and
conventions to be followed by EJB servers, containers, and beans. Writing EJB
components is straightforward: simply write code to implement your business logic, taking
care to follow the rules and conventions imposed by the EJB model.
EJB components can also run within the larger J2EE framework. In addition to the
standalone EJB component services, EJBs running within a J2EE server can be assembled
with other components (like web components) into J2EE applications.
Unlike some of the other Java Enterprise APIs, the EJB API is just the beginning of
understanding how EJB works. The key to understanding Enterprise JavaBeans lies in the
interactions among beans, containers, and the EJB server. These interactions are
described in detail in Chapter 6. In addition, the syntax for the abstract persistence
language used in entity EJBs, EJB QL, is described in Appendix C.
Java Enterprise in a Nutshell, 3rd Edition Page 21 Return to Table of Contents