
슈퍼타입 서브타입 논리 모델을 실제 물리 모델로 구현하는 방법
주요 어노테이션
@Inheritance(strategy=InheritanceType.XXX) @DiscriminatorColumn(name=“DTYPE”)@DiscriminatorValue(“XXX”)
@Inheritance(strategy = InheritanceType.JOINED), @DiscriminatorColumn
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn은 따로 작성하지 않아도 자동으로 기입됨
이 전략은 데이터베이스 설계자와 ORM 전문가 둘 다 추천 X
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
📍 @MappedSuperclass
em.find(BaseEntity) 불가) @MappedSuperclass
public abstract class BaseEntity {
private String createBy;
private LocalDateTime createdDate;
private String lastModifiedBy;
private LocalDateTime lastModifiedDate;
...
}
@Entity
public class Member extends BaseEntity {
...
}
@Entity
public class OrderItem extends BaseEntity {
...
}
@Entity 클래스는 엔티티나 @MappedSuperclass로 지정한 클래스만 상속 가능