Newsletter sign-up
View all newsletters

Sign up for our Enterprise Java Newsletter

Enterprise Java

Read all about EJB 2.0

Dramatic EJB 2.0 changes enhance flexibility and portability in your application development

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Enterprise JavaBeans 2.0, released June 2, is not just a point release but also a new version of the specification. At just over 500 pages, the EJB 2.0 specification is 200 pages (66 percent) longer than the previous EJB 1.1 specification. The most important changes in the specification are those made to container-managed persistence (CMP) and the introduction of a completely new bean type, the MessageDrivenBean.

The bulk of the changes in EJB 2.0 are found in the definition of a new CMP component model. It's radically different from the old CMP model because it introduces an entirely new participant, the persistence manager, and a completely new way of defining container-managed fields, as well as relationships with other beans and dependent objects.

The introduction of the MessageDrivenBean (the message bean) is also significant. The message bean represents the integration of JMS (Java Message Service) with EJB to create an entirely new type of bean designed to handle asynchronous JMS messages. That exciting new bean type provides a component model for JMS clients, allowing them to be deployed in the rich and robust environment of an EJB container system.

There are many other smaller changes made to the specification. Those other changes, while important, are mostly concerned with tightening the specification to eliminate ambiguities and make the components more portable. This article focuses on the new CMP and message bean component models introduced in EJB 2.0.

I provide several concrete examples, so it should be fairly easy to follow and comprehend. EJB novices might, however, find the material more difficult since it's assumed that readers have a basic understanding of EJB. For more information on EJBs, please see Resources.

Container-managed persistence

Container-managed persistence has undergone radical changes in EJB 2.0. In EJB 2.0, the persistence manager handles persistence of CMP entity beans automatically at runtime. The persistence manager is responsible for mapping the entity bean to the database based on a new bean-persistence manager contract called the abstract persistence schema. In addition, the persistence manager is responsible for implementing and executing find methods based on a new query language called EJB QL.

It's important to note that products that comply with the EJB 2.0 specification must support the EJB 1.1 CMP model as well as the new EJB 2.0 model. While those models are not compatible, support is required for the EJB 1.1 model to ensure backward compatibility.

The abstract persistence schema

To understand how the abstract persistence schema works and why it's important, I will quickly review for you how CMP is handled in EJB 1.1, and then discuss how it's defined in EJB 2.0.

The EJB 1.1 CMP model

In EJB 1.1, the bean developer is responsible for declaring the bean class' persistent fields as either Java primitive or serializable types. The following examples show an Employee enterprise bean class, as defined in EJB 1.1, with several CMP fields:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • More articles by Richard Monson-Haefel