Steve Chambers Steve Chambers - 1 month ago 10x
Java Question

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

I need to join from a superclass attribute to its subclass entity (they are 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


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.