Enterprise Java Development@TOPIC@

Chapter 63. Inheritance Strategy: Single Table

63.1. Single Table Strategy Overview
63.2. Single Table Example Database Schema
63.3. Single Table Example Java Mapping
63.4. Single Table Example Usage
63.5. @DiscriminatorColumn Annotation
63.6. Summary

  • Advantages

    • Simplest to implement

      • Single table to administer

    • Performs better than other inheritance strategies

      • No complex joins

  • Disadvantages

    • Unused fields when sub-types have unique properties

    • Sub-type columns must be nullable

      • Harder to enforce constraints within database

      • SQL "check" constraint can help

        check(TYPE != 'BREAD_TYPE' or (BAKEDON is not null and SLICES is not null))
        check(TYPE != 'Soup' or (SOUPTYPE is not null and EXPIRATION is not null)
    • Not normalized

  • More suitable for hierarchies with sub-types that...

    • Differ primarily in behavior only

    • Do not have unique data requirements


  • Single table

  • No joins

  • Unused columns


  • Parent defines default mapping for all derived types


  • Supplies type-specific column value


  • Accepts default type-specific column value


  • Two rows inserted into single base table with discriminator type supplied


  • Single table queried for objects


  • Single table "sparsely" filled based on type

@DiscriminatorColumn defines column to hold type-specific value