Inheritance
  • Entity classes can extend other entity classes
Entity Inheritance Example  
  • Non-entity superclasses having the @MappedSuperclass annotation will have their persistent state stored
@MappedSuperclass Inheritance Example  
  • Non-entity superclasses should be used to inherit behavior only, as their state is not persisted
Non-Entity Inheritance Example  
  public class Person { // Not queryable, not persisted!
    private String firstName, lastName;
    ...
    // Getters/Setters
    ...
  }

  @Entity
  public class Employee extends Person { // Queryable, but firstName and lastName not persisted!
    ...
  }