【问题标题】:JPA Inheritence Annotation on Sub Entity Hierarchy子实体层次结构上的 JPA 继承注释
【发布时间】:2014-02-18 12:33:26
【问题描述】:

是否可以在不同的层次使用@Inheritence Annotation 和不同的策略?

The inheritance strategy and the discriminator column are only specified in the root of an entity class
hierarchy or subhierarchy .

但允许不同的策略?

【问题讨论】:

    标签: java jpa orm jpa-2.0


    【解决方案1】:

    在单个实体继承层次结构中混合继承策略不是受支持的 JPA 配置。 JPA 规范指出:

    本规范未定义单个实体继承层次结构中的继承策略组合。

    【讨论】:

    • 所以最终结果是 no 或 support with any conflict 。
    • 正确的 JPA 没有定义行为。实现者可以定义一种行为,但是使用该行为是不可移植的。
    【解决方案2】:

    我不这么认为,如果我错了,请纠正我。您可以使用具有相同层次结构的mixed-inheritance 应用不同的策略。使用

    @SecondaryTable(
    name = "SUBTABLE",
    pkJoinColumns = @PrimaryKeyJoinColumn(name = "SUB_TABLE_ID");
    

    在您的子类定义之前。使用它,您可以应用例如SINGLE_TABLE 策略并分离子类表。

    【讨论】:

      猜你喜欢
      • 2010-12-21
      • 2014-10-26
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 2023-04-09
      • 1970-01-01
      相关资源
      最近更新 更多