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  
  @MappedSuperclass
  public abstract class AbstractEntity { // Not queryable, but persisted!
    private Long id;
    ...
    public Long getId() {
      return id;
    }
    ...
  }

  @Entity
  public class Employee extends AbstractEntity { // Queryable!
    ...
  }
  • Non-entity superclasses should be used to inherit behavior only, as their state is not persisted
Non-Entity Inheritance Example