O'Reilly logo

Enterprise JavaBeans 3.1, 6th Edition by Bill Burke, Andrew Lee Rubinger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. Entity Inheritance

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.

Customer class hierarchy
Figure 12-1. Customer class hierarchy

The Java Persistence specification provides three different ways to map an inheritance hierarchy to a relational database:

A single table per class hierarchy

One table will have all properties of every class in the hierarchy.

A table per concrete class

Each class will have a table dedicated to it, with all of its properties and the properties of its superclass mapped to this table.

A table per subclass

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.

Single Table per Class Hierarchy

In the single table per ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required