- Advantages of CMP Entity Beans over BMP Entity Beans
- CMP 2.0 Entity Bean Sample Application
- Step 1: Implementing the CMP 2.0 Address Entity Bean
- Step 2: Implementing the CMP 2.0 Roster Entity Bean
- Step 3: Implementing the CMP 2.0 Student Entity Bean
- Step 4: Implementing JSP Clients to Test CMP 2.0 Entity Beans
- Step 5: Packaging the CMP 2.0 Entity Beans as an ejb-jar File
- Step 6: Packaging the JSP As a Web Component
- Step 7: Deploying the CMP 2.0 Entity Bean Sample Application
- Step 8: Testing the Sample Application
- A Discussion of the Deployment Descriptor
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:
Implement the CMP 2.0 address entity bean (AddressEJB).
Implement the CMP 2.0 roster entity bean (RosterEJB).
Implement the CMP 2.0 student entity bean (StudentEJB).
Implement several JSP clients to test the CMP 2.0 entity beans.
Package the CMP 2.0 entity beans as EJB components.
Package the JSP as a Web component.
Deploy the CMP 2.0 entity bean sample application.
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.