background image

Persistence in the EJB Tier

<< rollback Method | Self-Referential Relationships >>
<< rollback Method | Self-Referential Relationships >>

Persistence in the EJB Tier

Persistence in the EJB Tier
This chapter describes how to use the Java Persistence API from enterprise beans. The material
here focuses on the source code and settings of two examples. The first example called order is
an application that uses a stateful session bean to manage entities related to an ordering system.
The second example is roster, an application that manages a community sports system. This
chapter assumes that you are familiar with the concepts detailed in
Chapter 24, "Introduction to
the Java Persistence API."
The order Application
The order application is a simple inventory and ordering application for maintaining a catalog
of parts and placing an itemized order of those parts. It has entities that represent parts,
vendors, orders, and line items. These entities are accessed using a stateful session bean that
holds the business logic of the application. A simple command-line client adds data to the
entities, manipulates the data, and displays data from the catalog.
The information contained in an order can be divided into different elements. What is the order
number? What parts are included in the order? What parts make up that part? Who makes the
part? What are the specifications for the part? Are there any schematics for the part? order is a
simplified version of an ordering system that has all these elements.
The order application consists of two modules: order-ejb, an enterprise bean JAR file
containing the entities, the support classes, and a stateful session bean that accesses the data in
the entities; and order-app-client, the application client that populates the entities with data
and manipulates the data, displaying the results in a terminal.
Entity Relationships in the order Application
The order application demonstrates several types of entity relationships: one-to-many,
many-to-one, one-to-one, unidirectional, and self-referential relationships.
26
C H A P T E R
2 6
711