@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
장점
단점
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DTYPE")
public abstract class Employee {
@Id @GeneratedValue
private Long id;
private String name;
}
@Entity
@DiscriminatorValue("FullTimeEmployee")
public class FullTimeEmployee extends Employee {
private int salary;
}
@Entity
@DiscriminatorValue("PartTimeEmployee")
public class PartTimeEmployee extends Employee {
private int hourlyRate;
}
@Inheritance(strategy = InheritanceType.JOINED)
장점
단점
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Employee {
@Id @GeneratedValue
private Long id;
private String name;
}
@Entity
@PrimaryKeyJoinColumn(name = "EMPLOYEE_ID")
public class FullTimeEmployee extends Employee {
private int salary;
}
@Entity
@PrimaryKeyJoinColumn(name = "EMPLOYEE_ID")
public class PartTimeEmployee extends Employee {
private int hourlyRate;
}
장점
단점
@MappedSuperclass
public abstract class BaseEntity {
private String name;
}
@Entity
public class FullTimeEmployee extends BaseEntity {
@Id @GeneratedValue
private Long id;
private int salary;
}
@Entity
public class PartTimeEmployee extends BaseEntity {
@Id @GeneratedValue
private Long id;
private int hourlyRate;
}