PowerDesigner supports various mapping strategies for inheritance persistence. Each strategy has its pros and cons, and you should select the most appropriate one for your needs. You can also apply mixed strategies, but this may not be well supported by your persistence framework.
Table per class hierarchy. All the classes in a hierarchy are mapped to a single table. The table has a column that serves as a "discriminator column". The value of this column identifies the specific subclass to which the instance that is represented by the row belongs.
In order to apply this kind of strategy, you should set the transformation type of leaf classes to Generate table and the transformation type of the other classes in the hierarchy to Migrate columns. PowerDesigner will only generate the tables for leaf classes. If you want to map other classes to tables, you need to create them manually.
Classes | Tables |
---|---|
|
|
Joined subclass. The root class of the class hierarchy is represented by a single table. Each subclass is represented by a separate table. This table contains the fields that are specific to the subclass (not inherited from its super class), as well as the column(s) that represent its primary key. The primary key column(s) of the subclass table serves as a foreign key to the primary key of the super class table.
In order to apply this kind of strategy, you should set the transformation type of all the classes to Generate table. You can also, optionally, define a discriminator.
Classes | Tables |
---|---|
|
|
Table per class. Each class is mapped to a separate table. All properties of the class, including inherited properties, are mapped to columns of the table for the class.
In order to apply this kind of strategy, you should set the transformation type of the root class to Generate table and the transformation type of other classes in the class hierarchy to Migrate columns.
For each class hierarchy, a discriminator is needed to distinguish between different class instances. You need to select one of the attributes of the root class in the Specifying Attribute list located in the property sheet of one of the children inheritance links of the root class. The attribute will be transformed into a discriminator column. In the following example, we define one extra attribute shapeType in Shape and select it as discriminator attribute:
Classes | Tables |
---|---|
|
|
Mixed Strategy - You can apply more than one strategy in the same inheritance hierarchy.
The transformation of entity classes with the Generate table transformation type will not change, but the transformation of those set to Migrate columns will be slightly different. If entity classes set to Migrate columns have both their super-class and sub-classes set to Generate table, the columns transformed from their persistent attributes will be migrated into tables transformed from sub-classes. The migration to sub-classes has higher priority.