我使用 SINGLE_TABLE 继承 startegy 来映射我的 usres(参见下面的代码示例)。
有没有办法将UnActiveRegularUser和UnActiveBusinessUser从“ACTIVE_USERS”表映射到另一个表,例如“UNACTIVE_USERS”并保持继承启动?
笔记:
- 这里的重点是避免 ex 之间的代码重复。RegularUser 与 UnActiveRegularUser(因为它们使用相同的属性)但仍将它们映射到 2 个不同的表:“ACTIVE_USERS”和“UNACTIVE_USERS”。
-strategy = InheritanceType.SINGLE_TABLE 不应更改。
- 添加另一个抽象层可以解决这个问题吗?
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "ACTIVE_USERS")
public class User {
@Id @GeneratedValue
protected Long id;
@Column(nullable = false)
protected String name;
}
@Entity
public class RegularUser extends User{
//more getters and settres
}
@Entity
public class UnActiveRegularUser extends User{
//same getters and setters as in RegularUser
}
@Entity
public class BusinessUser extends User {
//more getters and settres
}
@Entity
public class UnActiveBusinessUser extends User {
//same getters and setters as in BusinessUser
}
谢谢,内森