Chapter 9 Generating Persistent Objects for Java and JSF Pages


Table per Class Hierarchy Strategy

In this strategy, the whole class hierarchy is mapped to one table (see the O/R Mapping chapter). 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.

@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.

 


Copyright (C) 2007. Sybase Inc. All rights reserved.