background image

Single Table per Class Hierarchy Strategy

<< Entity Inheritance Mapping Strategies | Table per Concrete Class Strategy >>
<< Entity Inheritance Mapping Strategies | Table per Concrete Class Strategy >>

Single Table per Class Hierarchy Strategy

The Single Table per Class Hierarchy Strategy
With this strategy, which corresponds to the default InheritanceType.SINGLE_TABLE, all
classes in the hierarchy are mapped to a single table in the database. This table has a
discriminator column, a column that contains a value that identifies the subclass to which the
instance represented by the row belongs.
The discriminator column can be specified by using the
javax.persistence.DiscriminatorColumn
annotation on the root of the entity class
hierarchy.
TABLE 24­1
@DiscriminatorColumn
Elements
Type
Name
Description
String
name
The name of the column in the table to be used as
the discriminator column. The default is DTYPE.
This element is optional.
DiscriminatorType
discriminatorType
The type of the column to be used as a
discriminator column. The default is
DiscriminatorType.STRING
. This element is
optional.
String
columnDefinition
The SQL fragment to use when creating the
discriminator column. The default is generated by
the Persistence provider, and is
implementation-specific. This element is
optional.
String
length
The column length for String-based
discriminator types. This element is ignored for
non-String discriminator types. The default is
31. This element is optional.
The javax.persistence.DiscriminatorType enumerated type is used to set the type of the
discriminator column in the database by setting the discriminatorType element of
@DiscriminatorColumn
to one of the defined types. DiscriminatorType is defined as:
public enum DiscriminatorType {
STRING,
CHAR,
INTEGER
};
If @DiscriminatorColumn is not specified on the root of the entity hierarchy and a
discriminator column is required, the Persistence provider assumes a default column name of
DTYPE
, and column type of DiscriminatorType.STRING.
Entities
The Java EE 5 Tutorial · September 2007
694