Question

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?

Was it helpful?

Solution

This is not supported as of hibernate-entitymanager 4.3.4. This is what I found so far:

  1. @NamedAttributeNode can't be used to refer to superclass' attributes.
  2. includeAllAttributes=true will include all attributes including superclass' attributes.
  3. @NamedAttributeNode in subgraph can refer to superclass' attributes.

OTHER TIPS

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

According to this link, this is a Hibernate bug and claimed to be fixed in version 4.3.6

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top