Enterprise Java Development@TOPIC@

Chapter 66. Inheritance Strategy:Non-Entity

66.1. Non-Entity Strategy Overview
66.2. Non-Entity Example Database Schema
66.3. Non-Entity Example Java Mapping
66.4. Non-Entity Example Usage (Persist)
66.5. Summary

  • Advantages

    • Allows inheritance of non-entity classes

  • Disadvantages

    • No base entity to form queries across hierarchy (unlike TABLE_PER_CLASS)

    • Tables not normalized (like TABLE_PER_CLASS)

    • Parent columns repeated in each subclass table

  • More suitable for ...

    • Independent subclasses


  • Non-entity base class properties appear in subclass tables


  • Parent class is not a legal entity -- has no @Id

Note

In this example, the implementation of BaseObject actually has an id attribute that the derived classes make use of. However, it is marked as @Transient in the base class and @Id in the derived Entity classes since MappedSuperClasses do not have primary keys. This specific example could have also used TABLE_PER_CLASS because of the availability of an id property in the base class.


  • "version" column name from parent being renamed

  • "id" property defined in this class given custom column name

  • Transient attribute in parent being reused to hold @Id for subclass using PROPERTY access


  • Entity accepts mapping defaults


  • Rows are inserted into type-specific entity class tables


  • Separate tables are accessed when obtaining each type


  • Separate tables per concrete class (like TABLE_PER_CLASS)

  • No unused columns (like TABLE_PER_CLASS)