A table-per-concrete-class inheritance strategy (figure ment number of the department to which the employee
4) maps each nonabstract class to its own table and maps belongs. The DEPT column in the EMPLOYEE table has a
each field to a column in the mapped table. This strategy constraint declared on it so that the value of the DEPT
reduces the number of tables needed to represent the column of any row of the EMPLOYEE table must be a value
domain classes. that is also contained in the primary-key column of the
A mixed inheritance strategy might use a combination DEPARTMENT table.
of strategies. For example, it might map the fields from A foreign-key constraint can be mapped to multiple
Person and Employee to one table that includes a discrimi- relationship fields in the domain object model. For exam-
nator column; map the fields from Full TimeEmployee to a ple, the DEPT column maps to two relationship fields in
second table; and map the fields from Part TimeEmployee the object model: the Employee class contains a reference
to a third table. to Department; and the Department class contains a set of
The benefits of single-table inheritance mapping are references to Employee.
simplicity and performance. To query for instances of any If the foreign-key column is unique, then only one
of the classes in the hierarchy, only a single table needs row in the table relates to the same row in the other table.
to be used. The disadvantage of single-table inheritance is In figure 6, an INSURANCE table has an EMPLOYEE column
that it might require many
columns that are used by
only a few class mappings. Tab le Per Concrete Class Inheritance Strategy
This inefficiency might be <<table>> <<table>>
an issue with very wide PERSON FULL_TIME_EMPLOYEE
<<FK>>
inheritance hierarchies. <<PK>>+PERSON_ID : int4 -PERSON_ID : int4
The benefits of other +FIRST_NAME : char varying
+LAST_NAME : char varying <<FK>> -WEEKLY_SALARY : currency
+EMPLOYEE_ID : int4
inheritance mapping strat- +MIDDLE_NAME : char varying -HIRE_DATE : date
egies are that the schema
can be completely normal- <<table>>
ized. The primary disad- PART_TIME_EMPLOYEE
vantage of inheritance -PERSON_ID : int4
mapping strategies that do +HOURLY_WAGE : currency
+EMPLOYEE_ID : int4
not include a discriminator -HIRE_DATE : date
column is performance.
Most queries for instances
of subclasses require an
outer join of the tables in F IG 4
the hierarchy, and these
queries are notoriously difficult to optimize.
Relationships. In relational schemas, relation-
0.. 1
ships are modeled via
foreign keys, defined as a
constraint on the values
that columns are allowed
to contain, based on values <<table>> <<table>> EMPLOYEE DEPARTMENT
contained in rows of other <<FK>>
-ID : int4 -ID : int4
tables. This constraint is -DEPT : int4 -NAME : char varying
enforced by the database.
As shown in figure 5, an
EMPLOYEE table might
contain a DEPT column
that contains the depart-
O ne to Many Mapping
Employee
-dept : Department
-id : int4
-insurance : Insurance
Department
0..*
-employees : Set<Employee>
-id : int4