Java Reference
In-Depth Information
<<interface>>
Coupon
PendingOrder
LineItem
PendingOrder
Percentage
Discount
Coupon
FreeShipping
Coupon
Restaurant
MenuItem
<<interface>>
Restaurant
Repository
EJB3Restaurant
Repository
javax.persistence
Entity
Manager
....
Figure 10.2
The EJB 3 versions of the domain model entities and repositories
POJO s to configure the entity beans and define their O/R mapping. However, the
limitations we saw earlier make it more difficult than it should be.
Implementing the PendingOrder entity bean
The first class we'll look at is the PendingOrder class. This class is interesting
because it uses several ORM features. It has simple fields, embedded objects, an
ordered unidirectional one-to-many-relationship, and two many-to-one relation-
ships, including a polymorphic reference. As you learned in chapters 5 and 6,
persisting this class with Hibernate and JDO is very straightforward. So what
about when using EJB 3 ?
It turns out that persisting this class with EJB 3 is not as easy. We can easily map
most fields and relationships to the database, but EJB 3 does not make it easy to
persist the line items. The two main challenges are how to preserve the ordering
of the lineItems collection, which is of type List<PendingOrderLineItem> , and
how to delete a line item when it is removed from the lineItems collection. If we
 
Search WWH ::




Custom Search