Table Per Class Hierarchy Strategy

In this strategy, the whole class hierarchy is mapped to one table. You can optionally define discriminator values for each Entity class in the hierarchy on the EJB 3 Persistence tab of the class property sheet.

Option

Description

Discriminator value

Specifies a value that distinguishes individual this class from other classes.

The Inheritance annotation with SINGLE_TABLE strategy is generated. The DiscriminatorColumn annotation is generated to define the discriminator column. The DiscriminatorValue annotation is generated to specify the value of the discriminator column for entities of the given type if you specify it for the class.

For more informations about mapping, see O/R Mapping Modeling.

@Entity(name="Shape")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="shapeType", discriminatorType=DiscriminatorType.STRING, length=100)
@Table(name="Shape")
public class Shape { ... }

@Entity(name="Rectangle")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue("Rectangle")
@Table(name="Shape")
public class Rectangle extends Shape { ... }

A model check is available to verify that discriminator columns are correctly defined.