O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Exercise 11.2: A Stateful Session Bean

In this exercise, you will build and examine a stateful session bean, TravelAgent, which coordinates the work of booking a trip on a ship. You will also build a client application to test this EJB.

Our version of this exercise does not follow the one in the EJB section strictly. Instead of simplifying the beans and their relationships as the EJB section does, we use the beans implemented in Chapter 6 and Chapter 7 and thus take advantage of the CMP 2.0 features of JBoss.

Examine the EJB

This exercise is based on the EJBs from Exercise 7.3 and doesn’t contain much material that previous sections haven’t covered. Nevertheless, a few modifications have been made:

  • The Customer EJB again has a remote home and bean interfaces (as in Chapter 6) and exposes its relationship with the Address EJB in the remote interface through a new data object, AddressDO.

  • The Cabin EJB has a new create method that takes several parameters.

  • The Reservation EJB has a new create method that takes several parameters, and has a local reference to the Customer EJB.

The TravelAgent bean’s role is to perform all activities needed to book a successful trip. Thus, as in the preceding example, this session bean acts as a coordinator between different EJBs and groups several actions on different beans in the same transaction. Here, though, the bean maintains a conversational state with the client; i.e., each client has a dedicated bean on the server.

In the previous example featuring ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required