Enterprise JavaBeans

Enterprise JavaBeans is a very big topic, and we can’t do more than provide a few paragraphs to whet your appetite. If you want more information, see Enterprise JavaBeans by Richard Monson-Haefel (O’Reilly & Associates). The thrust of EJB is to take the JavaBeans philosophy of portable, pluggable, components and extend it to accommodate the sorts of things that three-tiered networked and database-centric applications require. Although EJB is built on the basic JavaBeans concepts, it is much larger and more “special-purpose.” It doesn’t have a lot in common with the kinds of things we’ve been talking about in this chapter. EJBs are primarily server-side components for networked applications. Sun’s Forte development environment, among others, provides some support for working with Enterprise JavaBeans.

EJB ties together a number of other Java “enterprise"-oriented APIs, including database access, transactions, and name services, into a single component model for server applications. EJB imposes a lot more structure on how you write code than plain old JavaBeans. But it does so in order to allow the server-side EJB container to take on a lot of responsibility for you and to optimize your application’s activities without you having to write a lot of code. Here are a few of the things that Enterprise JavaBeans tackles:

  • Object lifecycle and name service lookup

  • Container-managed persistence

  • Transaction management

  • Server resource pooling and management

  • Deployment configuration

EJB divides the world into two camps: Entity Beans , which represent data objects, and Session Beans, which implement services and operations over entity beans. These correspond well to the second and third tiers in a three-tiered business application. "Business Logic” is represented by Session Bean services and database access is made transparent through automated object mapping by Entity Beans.

Many aspects of EJB behavior can be controlled through "deployment descriptors” that customize bean behavior for the local environment. The result is a high level of abstraction over ordinary business-specific code. It allows powerful, networked business application components to be packaged and reused in the sort of way that ordinary Beans are reused to build client-side applications.

Sun has created a reference EJB platform as part of Java 2 Enterprise Edition (J2EE); currently, the most robust EJB implementations are provided by third-party companies. Usually the EJB "container” is packaged as part of a more general “application server” that performs other duties such as providing a web server. There are many vendors of commercial EJB servers. Two extremes: Weblogic makes a very popular one with many high-end features; Valto’s Ejipt is a very small (embeddable) EJB container.

Get Learning Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.