InheritanceType.SINGL和InheritanceType.JOINED如何同时显示一个类

时间:2018-08-25 07:41:27

标签: java hibernate jpa annotations

有一些这样的JPA注释类:

@MappedSuperclass
public abstract class BaseEntity<T> implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="sequence_db")
private T id;

//Some other fields with its getter & setter

}

另一个类是:

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "BASE_OFFIC")
@DiscriminatorColumn(name = "discriminator_col")
@SequenceGenerator(name = "sequence_db" , sequenceName = "SEQ_BASE_OFFIC", allocationSize = 1)
public class BaseOffic extends BaseEntity<Integer>{

//Some other fileds here with its getter & setter methods

BaseOffic扩展过来的第三类是这样的:

@Entity
@DiscriminatorValue("real_offic")
public class Offic extends BaseOffic {

//some other fields with its getter & setter

}

如您所见,Offic和BaseOffic均为InheritanceType.SINGLE_TABLE

通过这种设计,所有事物都可以正常工作,但是我被迫执行以下任务:
Offic类继承自Inheritance.JOINED ,这是第四类,而您在上面看到的当前设计没有改变

另一方面,Offic类既是InheritanceType.SINGLE_TABLE的{​​{1}},又是我要创建的第四类的BaseOffic

执行此操作以使两种情况都可行的正确语法是什么?


已编辑
第四类是这样的:

Inheritance.JOINED

我希望此类为Inheritance.JOINED与public class [class_name] extends Offic { .... }

0 个答案:

没有答案