MappedSuperclass

We use @MappedSuperclass to have a bean that holds common properties. For example:

@MappedSuperclass
public abstract class BaseDomain {

  @Id
  long id;

  @Version
  long version;

  @WhenCreated
  Instant whenCreated;

  @WhenCreated
  Instant whenModified;


  // plus getters and setters ...

}

We then create entity beans that extend the MappedSuperclass bean.

@Entity
public class Customer extends BaseDomain {

  String name;

  @ManyToOne
  Address billingAddress;

  ...
}