In order to be complete, an object-to-relational mapping engine must support inheritance hierarchies. The Java Persistence specification supports entity inheritance, polymorphic relationships/associations, and polymorphic queries. These features were completely missing in the older EJB CMP 2.1 specification.
In this chapter, we’ll modify the
Employee entity that we defined in earlier
chapters to make it fit into an inheritance hierarchy. We’ll have it extend
a base class called
Person and redefine the
Employee class to extend a
Customer class. Figure 12-1 shows this class hierarchy.
The Java Persistence specification provides three different ways to map an inheritance hierarchy to a relational database:
One table will have all properties of every class in the hierarchy.
Each class will have a table dedicated to it, with all of its properties and the properties of its superclass mapped to this table.
Each class will have its own table. Each table will have only the properties that are defined in that particular class. These tables will not have properties of any superclass or subclass.
In this chapter, we use these three strategies to map the
Employee class hierarchy defined in Figure 12-1.
In the single table per ...