Java Reference
In-Depth Information
the
PENDING_ORDER_LINE_ITEM
table has a
LINE_ITEM_INDEX
column, which
stores the position of the line item in the list.
One-to-many relationships are often
whole-part
relationships, which are rela-
tionships where the part cannot exist independently of the whole. A part must be
deleted if either the whole is deleted or the part is no longer associated with the
whole. Examples of whole-part relationships in the Food to Go domain model are
PendingOrder
-
PendingOrderLineItem
and
Restaurant
-
MenuItem
. A line item or
menu item cannot exist independently of its
PendingOrder
or
Restaurant
. As I
describe later, it is extremely useful if an ORM framework directly supports whole-
part relationships.
Mapping many-to-many relationships
A relationship called A-B is many-to-many when a B object can be referenced by
multiple A objects. For example, if a customer could use multiple coupons when
placing an order, then
PendingOrder
-
Coupon
relationship would be many-to-many
instead many-to-one. A
PendingOrder
could have multiple coupons and a coupon
could be used by multiple
PendingOrder
s:
public class PendingOrder {
private List coupons;
…
}
public class Coupon {
…
}
A many-to-many relationship is mapped using a join table that has foreign keys to
both classes' tables. The
PendingOrder
-
Coupon
relationship can be mapped as follows:
CREATE TABLE PENDING_ORDER (
PENDING_ORDER_ID,
…
)
CREATE TABLE COUPON (
COUPON_ID
…
)
CREATE TABLE PENDING_ORDER_COUPON (
PENDING_ORDER_ID
COUPON_ID
)
Search WWH ::
Custom Search