Java Reference
In-Depth Information
Configuring JPA to use the table-per-class strategy is the easiest of all the strategies. The
following listing shows how to configure JPA using the table-per-class strategy.
Listing 9.23. The table-per-class stragegy
This listing shows that the @Inheritance annotation's strategy element is specified as
TABLE_PER_CLASS . Of course, the @DiscriminatorColumn and @Discrim-
inatorValue annotations are absent from this listing—they have no use because all the
data for each entity is stored in its own table, so there's no need to distinguish which re-
cords are bidders and which are sellers. Finishing the code example, the @Table annota-
tion is used to map each entity to its table (
,
, and
).
This strategy is the hardest for a persistence provider to implement reliably. As a result, im-
plementing this strategy has been made optional for the provider by the specification. We
recommend that you avoid this strategy altogether.
This completes our analysis of the three strategies for mapping OO inheritance. Choosing
the right strategy isn't as straightforward as you might think. Table 9.4 provides an overall
comparison of each strategy.
Table 9.4. Summary of OO hierarchy inheritance mapping strategies
Feature
Single-table
Joined-tables
Table-per-class
One for the parent class, and
each subclass has a separate
table to store polymorphic
One table for all classes in
the entity hierarchy:
One table for each concrete
class in the entity hierarchy.
Table support
 
Search WWH ::




Custom Search