混合JPA继承策略-带有牢靠继承类型.SINGLE_TABLE的InheritanceType.JOINED [英] mixing jpa inheritance strategies - inheritanceType.JOINED with inheritanceType.SINGLE_TABLE

查看:166
本文介绍了混合JPA继承策略-带有牢靠继承类型.SINGLE_TABLE的InheritanceType.JOINED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的类结构如下...我在这里实现了两个单独的策略,但是根类的继承策略即InheritanceType.JOINED在整个层次结构中都在使用...

My class structure looks like this... I have two separate strategies being implemented here but the inheritance strategy of the root class i.e. InheritanceType.JOINED is being used throughout the hierarchy...

@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'的表...
我发现有几个人在问同样的问题...但是答案并没有帮助我...

混合联接和单表继承并查询所有对象-相同的问题.
如何将继承策略与JPA批注和Hibernate混合?-将single_table与Join.混合使用.

When, I am creating an instance of 'D' and trying to persist it, hibernate is looking for a table named 'D' ...
I found a couple of people asking the same questions... but answers didn't help me...

mixing joined and single table inheritance and querying for all objects - same issue..
How to mix inheritance strategies with JPA annotations and Hibernate? - mixing single_table with joined.. this is not helpful in my case..

推荐答案

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

The JPA spec does not allow you to mix strategies in an inheritance tree; it requires you to set the inheritance strategy in the root Entity. JDO is the only spec allowing mixed strategies. You may find a JPA implementation that allows it, but it is non-portable

这篇关于混合JPA继承策略-带有牢靠继承类型.SINGLE_TABLE的InheritanceType.JOINED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆