2012-04-03 113 views
1

我的类结构看起来像这样...我有两个单独的策略在这里实现,但是继承策略的根类,即InheritanceType.JOINED被用于整个层次结构...混合jpa继承策略 - inheritanceType.JOINED with inheritanceType.SINGLE_TABLE

@Entity 
@Inheritance(strategy = InheritanceType.JOINED) 
@DiscriminatorColumn(name = "typeName", discriminatorType = DiscriminatorType.STRING, length = 100) 
@Table(name="table_A") 
public abstract class A{ 
... 
} 


@Entity 
@Table(name = "table_B") 
@PrimaryKeyJoinColumn(name = "ID_B") 
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) 
@DiscriminatorValue("SVC") 
public abstract class B extends A { 
... 
} 

@Entity 
@DiscriminatorValue("C") 
public class C extends B { 
... 
} 

@Entity 
@DiscriminatorValue("D") 
public class D extends B { 
... 
} 

时,我创建“d”的实例,并试图坚持它,Hibernate是寻找一个名为“d”表...
我发现一对夫妇的人问同样的问题...但答案并没有帮助我...

mixing joined and single table inheritance and querying for all objects - 同样的问题..
How to mix inheritance strategies with JPA annotations and Hibernate? - 混合single_table与joined ..这对我的情况没有帮助..

+0

我发现一个[解决方案](http://stackoverflow.com/questions/40679517/how-to-mix-inheritance-type-in​​- jpa)只使用没有Hibernate的JPA openJPA。 – 2016-11-24 08:50:17

回答

2

JPA规范不允许您在继承树中混合策略;它要求您在根实体中设置继承策略。 JDO是允许混合策略的唯一规范。你可能会发现一个允许它的JPA实现,但它不可移植