Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

CMP 2.0 Entity Bean Sample Application

The CMP 2.0 entity bean application that we describe in this chapter allows students to create their user IDs, add one or more addresses, and register for classes. It also allows the student to list the addresses and classes for which they are currently registered. The application consists of several JSP clients that invoke create and search methods on three CMP 2.0 entity beans: StudentEJB, AddressEJB, and RosterEJB.

Let's examine the relationships among these three EJBs. A student can have zero or more addresses; as such, the student-address relationship is one-to-many and is a unidirectional relationship, navigating from student to address. When the student account is deleted, the address must also be deleted, requiring the use of a cascade delete option. The relationship between the student and the roster can be many-to-many (for example, a student can enroll in many classes, and a class can have many students); but, for simplicity, the relationship between student and roster is specified as one-to-many. There is no directional relationship between the address and the roster except via the student.

StudentEJB, AddressEJB, and RosterEJB are implemented as CMP 2.0 entity beans with local interfaces. The home and component interfaces of these EJBs are described and implemented in this chapter.

Steps necessary to implement CMP 2.0 entity beans are similar to the steps for implementing BMP entity beans; however, although coding for CMP entity beans is simpler, deployment is more complicated. The tasks involved in the development and deployment of the sample application include, in sequence:

  1. Implement the CMP 2.0 address entity bean (AddressEJB).

  2. Implement the CMP 2.0 roster entity bean (RosterEJB).

  3. Implement the CMP 2.0 student entity bean (StudentEJB).

  4. Implement several JSP clients to test the CMP 2.0 entity beans.

  5. Package the CMP 2.0 entity beans as EJB components.

  6. Package the JSP as a Web component.

  7. Deploy the CMP 2.0 entity bean sample application.

  8. Test the sample application.

We'll conclude with a discussion of the deployment descriptor, which results from steps followed during the packaging of an application.

  • + Share This
  • 🔖 Save To Your Account