Java Reference
In-Depth Information
Table per hierarchy
One ORM approach is to map all of the classes in an inheritance hierarchy to a
single table. For example, we can map the Coupon hierarchy to the COUPON table
as follows:
CREATE TABLE COUPON (
CODE VARCHAR2(30),
COUPON_TYPE VARCHAR2(100),
MINIMUM NUMBER(10,2),
PERCENT_DISCOUNT NUMBER(5,2),
);
The COUPON table has columns that store the fields of all three classes:
CODE : Stores the coupon code from the FreeShippingCoupon and Percentage-
DiscountCoupon classes
MINIMUM : Stores the minimum quantity from the FreeShippingCoupon and
PercentageDiscountCoupon classes
PERCENT_DISCOUNT : Stores the percentage discount from PercentageDis-
countCoupon
It also has a COUPON_TYPE column, which is a discriminator column that stores the
type of each coupon.
This approach has the following benefits:
It uses the minimum number of SQL statements and joins to access and
manipulate objects because they are stored in a single table. Finding objects
requires a SELECT statement that references a single table, and updating and
creating objects requires a single INSERT or SELECT statement.
A reference to a superclass is simply mapped as a foreign key to a single
table. For example, the PendingOrder - Coupon relationship is mapped to a
foreign key from the PENDING_ORDER to the COUPON table.
This approach has the following drawbacks:
A row can have unused columns because only those columns that corre-
spond to one subclass's fields are used. This can potentially result in ineffi-
cient storage utilization and unnecessary traffic between the application
and the database. It can prevent you from defining the correct database
schema constraints. For example, the DISCOUNT_PERCENTAGE column is only
used in those rows that represent instances of PercentageDiscountCoupon ,
and so we cannot define the DISCOUNT_PERCENTAGE column as NOT NULL .
 
Search WWH ::




Custom Search