Java Reference
In-Depth Information
Let's look at the details:
B
@Entity annotation specifies that PendingOrder is an entity bean and the access =
AccessType.FIELD member specifies that its fields are mapped
The @Id annotation specifies that the id field stores the primary key and that the
EJB container should pick the most appropriate primary key generation mecha-
nism for the database.
The @Column annotation for the deliveryTime field specifies that it maps to the
DELIVERY_TIME column.
The restaurant field has an @ManyToOne annotation, which specifies that the rela-
tionship is many-to-one, and an @JoinColumn , which specifies that the foreign key
column in the PENDING_ORDER table is called RESTAURANT_ID .
The lineItems field has two standard annotations: an @OneToMany annotation,
which specifies that the relationship is one-to-many, and an @JoinColumn attribute,
which specifies that the foreign key in the PENDING_ORDER_LINE_ITEM table is
called PENDING_ORDER_ID . It also has two JBoss extensions: @IndexColumn , which
automatically maintains the index, and @Cascade , which automatically deletes
orphaned children.
C
D
E
F
G
The coupon field has an @ManyToOne annotation that specifies that the field is really
a reference to an AbstractCouponImpl . You'll learn why in a moment.
The @Embedded and @AttributeOverride annotations for the deliveryAddress and
paymentInformation fields define the O/R mapping for the fields of the embed-
ded objects.
H
Implementing the Restaurant entity bean
The Restaurant class is the next class we are going to examine. We must solve two
issues in order to persist this class with EJB 3 . The first is how to persist Restau-
rant.serviceArea , which is of type Set<String> and is not supported by EJB 3 . To
persist this field we must change the serviceArea field to Set<ZipCode> and
define a ZipCode entity, which is a wrapper around a String .
The second problem we must address is how to preserve the ordering of the
menuItem field, which is a List<MenuItem> . As with the PendingOrder.lineItem
field we have two options. We can either add an index field to the MenuItem class
or we can use a vendor-specific extension. Once again I'm going to use the JB oss
extensions to avoid writing extra code.
Here is part of the code for the Restaurant class:
 
 
 
 
Search WWH ::




Custom Search