Reputation: 1758
I've the following mapping in my project:
@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 {
...
}
All collection assosications are lazy by default. My goal is to create an entity graph that can be used to eagerly load PurchaseInvoice.lineItems
and PurchaseInvoice.payment.paymentTerms
.
If I define the following entity graph:
@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
I got the following Unable to build entity manager factory error:
java.lang.IllegalArgumentException: Unable to locate Attribute with the given name [lineItems] on this ManagedType [PurchaseInvoice]
What is the proper way to refer to an attribute in superclass (or subclasses) in JPA 2.1 entity graph?
Upvotes: 3
Views: 6417
Reputation: 4821
According to this link, this is a Hibernate bug and claimed to be fixed in version 4.3.6
Upvotes: 0
Reputation: 1758
This is not supported as of hibernate-entitymanager 4.3.4. This is what I found so far:
@NamedAttributeNode
can't be used to refer to superclass' attributes.includeAllAttributes=true
will include all attributes including superclass' attributes.@NamedAttributeNode
in subgraph can refer to superclass' attributes.Upvotes: 5
Reputation: 86
Maybe it is a simple syntax- problem in the definition of the graph? In my opinion the definition does not contain square brackets. I've tested your code and it was ok.
See:Developerblog
Upvotes: 1