我有以下的课堂结构:
我想用hibernate生成以下三个表:
计划项:及其所有属性
任务:具有所有属性及其子属性
阶段:具有所有属性
我试着混合继承类型,但没有成功:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class PlanItem {...}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Stage extends PlanItem {...}
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Task extends PlanItem {...}
@Entity
public class HumanTask extends Task {...}
@Entity
public class ProcessTask extends Task {...}
@Entity
public class CaseTask extends Task {...}
我已经用二级表做了实验,得到了或多或少想要的结果:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class PlanItem {...}
@Entity
@SecondaryTable( name = "Stage" )
public class Stage extends PlanItem {...}
@Entity
@SecondaryTable( name = "Task" )
public class Task extends PlanItem {...}
@Entity
@SecondaryTable( name = "Task" )
public class HumanTask extends Task {...}
@Entity
@SecondaryTable( name = "Task" )
public class ProcessTask extends Task {...}
@Entity
@SecondaryTable( name = "Task" )
public class CaseTask extends Task {...}
但我想知道是否有更优雅和简单的解决方案呢?
最佳答案
这目前是不可能的,请参阅following issue了解更多信息。我认为你的“黑客”使用二级表是目前最好的。
关于java - 多层次层次结构的Hibernate混合继承策略,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42504591/