我的项目中有以下映射:
@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.lineItems
和PurchaseInvoice.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 实体图中引用超类(或子类)中的属性的正确方法是什么?