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 ...

Get Enterprise JavaBeans, Fourth Edition 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.