JPA 2.1 shows examples of using multiple downcasts in a restriction: 4.4.9 Downcasting
SELECT e FROM Employee e WHERE TREAT(e AS Exempt).vacationDays > 10 OR TREAT(e AS Contractor).hours > 100 6.5.7 Downcasting Example 3: CriteriaQuery<Employee> q = cb.createQuery(Employee.class); Root<Employee> e = q.from(Employee.class); q.where( cb.or(cb.gt(cb.treat(e, Exempt.class).get(Exempt_.vacationDays), 10), cb.gt(cb.treat(e, Contractor.class).get(Contractor_.hours), 100))); These don't work in Hibernate for joined inheritance because Hibernate uses an inner join for the downcasts. I've added a FailureExpected test case for this: https://github.com/hibernate/hibernate-orm/commit/1ec76887825bebda4c02ea2bc1590d374aa4415b IIUC, inner join is correct when TREAT is used in a JOIN clause. If TREAT is only used for restrictions in the WHERE clause, I *think* it should be an outer join. Is that correct? HHH-9862 also mentions that Hibernate doesn't work properly when there are multiple select expressions using different downcasts, as in: CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Object[]> query = cb.createQuery(Object[].class); Root<Pet> root = query.from(Pet.class); query.multiselect( root.get("id"), root.get("name"), cb.treat(root, Cat.class).get("felineProperty"), cb.treat(root, Dog.class).get("canineProperty") ); I don't think this should work, at least not with implicit joins. Is this valid? Thanks, Gail _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev