Hi
Can the Criteria API / CriteriaBuilder be used with Inheritance/Polymorphism? e.g.
entity A valueA entity B extends A valueB entity C extends A valueC
When I select entity A in JP-QL, I have automatically access to the attributes valueA, valueB and valueC and they are null if a given object does not belong the the corresponding subtype. This allows to to create queries returning all three types of objects and specifying filters on any of the properties.
With the CriteriaBuilder this does not work since it is strongly typed: root = criteriaQuery.from(A.class) criteriaQuery.select(root.get("valueB"))
Naturally, I could use from(B.class), but then I would loose the ability to return all three types of objects in a single query. Or is there at any possibility to specify an outer/left join to the subtypes so that I could access the child properties trough the join?
With JPA 2.1 there will be a "TREAT AS ..." feature which does exactly that.
Thanks, Regards Remo
|