Steve Chambers Steve Chambers - 1 year ago 111
Java Question

How to join to a JOINED subclass in Hibernate / JPA 2.0 in a CriteriaQuery?

I need to join from a superclass attribute to its subclass entity (using JOINED inheritance). Tried something like this:


...and need to continue this by joining from the subclass to other entities.
But the
is returning a
so not sure how this is possible?

(Note: Am using JPA 2.0, not 2.1 so can't use

Answer Source

In the end I got it working by constructing the query the other way round - so instead of attempting to join to a subclass it was simply using the parent metamodel class:


This worked for my use case but expect there may still be situations where the question needs a better answer - e.g. where the required set of joins includes both children and parents.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download