如何在Hibernate JPA @NamedEntityGraph中引用继承的属性?

乔基

我的项目中有以下映射:

@Embeddable
class LineItem {
    ...
}

@Entity
abstract class Invoice {
    ...
    @ElementCollection @OrderColumn @NotEmpty
    List<LineItem> lineItems = []
    ...
}

@Entity
class PurchaseInvoice extends Invoice {
    ...
    @OneToOne(cascade=CascadeType.ALL, orphanRemoval=true)
    Payment payment
    ...
}

@Entity
class Payment {
    ...
    @ElementCollection @OrderColumn
    List<PaymentTerm> paymentTerms = []
    ...
}

@Embeddable
class PaymentTerm {
    ...
}

默认情况下,所有集合关联都是惰性的。我的目标是创建一个实体图,该图可用于热切加载PurchaseInvoice.lineItemsPurchaseInvoice.payment.paymentTerms

如果我定义以下实体图:

@NamedEntityGraph(name='PurchaseInvoiceWithDetail', attributeNodes = [
     @NamedAttributeNode(value='payment', subgraph='payment'),
     @NamedAttributeNode(value='lineItems')
], subgraphs = [
     @NamedSubgraph(name='payment', type=Payment, attributeNodes = [
         @NamedAttributeNode(value='paymentTerms')
     ])
])
@Entity
class PurchaseInvoice extends Invoice

我收到以下无法建立实体管理器的工厂错误:

java.lang.IllegalArgumentException: Unable to locate Attribute  with the given name [lineItems] on this ManagedType [PurchaseInvoice]

在JPA 2.1实体图中引用超类(或子类)中的属性的正确方法是什么?

乔基

从hibernate-entitymanager 4.3.4开始不支持此功能。这是我到目前为止发现的:

  1. @NamedAttributeNode 不能用于引用超类的属性。
  2. includeAllAttributes=true 将包括所有属性,包括超类的属性。
  3. @NamedAttributeNode 子图中的可以引用超类的属性。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在JPA中复制Hibernate的saveOrUpdate?

如何在JPA / Hibernate的孩子的ID中引用父母的ID?

当涉及继承时,如何在Hibernate / JPA中指定列名?

如何在 JPA/Hibernate 中概念化 @OneToMany 映射

如何在Hibernate / JPA中实现“可选”关系?

如何在Spring Data JPA中设置Hibernate命名策略

如何在 Spring Boot 中捕获 hibernate/jpa 约束违规?

如何在JPA Hibernate中对外部列进行排序?

如何在JPA中混合继承类型

如何在Spring Data JPA @Modifying @Query查询中更新JPA / Hibernate @Version字段?

如何在Spring JPA Web应用程序中设置一些Hibernate属性?

如何在JPA和Hibernate中使用关联实体处理循环引用

JPA-如果AccessType为“属性”,如何在查询中引用属性?

如何在运行时设置 spring.jpa.hibernate.dialect 属性?

如何在MySQL 4中使用jpa在hibernate 4中动态添加列?

如何在Spring Boot中使用hibernate / jpa在mysql关系表中插入数据

如何在Spring JAVA(JPA / Hibernate)中映射MySQL时间戳字段

如何在JPA和Hibernate中合并实体时避免java.util.ConcurrentModificationException

如何在Spring Boot JPA / Hibernate中获取ddl自动生成的脚本?

如何在JPA / Hibernate应用程序中配置连接池(没有Spring)?

如何在Spring Controller中获取与JPA和Hibernate的FetchType.LAZY关联

如何在Netbeans 8中将Hibernate 5.2与JPA 2一起使用

如何在Hibernate JPA中添加可编程的实体侦听器

如何在Hibernate / JPA中保留EnumMap

如何在Hibernate / JPA中使用@Formula

继承JPA和Hibernate问题

如何在地图上的MySQL JSON列使用JPA和Hibernate一个Java实体属性 -

在JPA / Hibernate中创建仅保存属性

JPA /如何在ManyToMany关系中添加属性