Datasheet
❑ Create a single table using the attributes from the lowest child.
❑ Create a table per class.
❑ Create a table per concrete class.
Let’s consider each of these inheritance mappings using the CD and SpecialEditionCD classes
as examples.
Lowest-Child Inheritance Mapping
If we have a hierarchy of classes, our mapping needs to be able to handle both the CD and
SpecialEditionCD classes using a single table. We can accomplish this by taking all the attributes for the
lowest child in the inheritance chain, mapping them, and then moving up the chain until we’ve mapped
the topmost parent. The result is a table with attributes from all classes. Using our two classes, this pro-
cess produces a table like the one in Figure 1.3.
create table cd (
ID int not null primary key auto_increment,
type varchar(256),
title varchar(256),
artist varchar(256),
newFeatures varchar(256),
count int
);
Figure 1.3
If we have an object of type SpecialEditionCD, all the necessary columns are available to persist it to the
database. If we have a CD object, all the necessary columns are still available; however, both the
CD
SpecialEditionCD
-newFeatures : String
-count : int
+getNewFeatures : String
+getCount : String
+setNewFeatures()
+setCount()
CD
-title : String
-artist : String
+getTitle : String
+getArtist : String
+setTitle()
+setArtist()
ID : int
type : varchar(256)
title : varchar(256)
artist : varchar(256)
newFeatures: varchar(256)
count : int
cd_tracks
ID : int
cd_id : int
name : varchar(256)
length : int
9
Introduction to Mapping Objects to Relational Databases
03_576771_c01.qxd 9/1/04 12:09 PM Page 9










