I\'m trying to achieve something like the following, using the JPA Criteria API:
SELECT b FROM Box b JOIN SpecialItem s WHERE s.specialAttr = :specialAttr
I just want to extend the answer of Chris for the Criteria API with generated meta-model.
CriteriaQuery<Box> q = cb.createQuery(Box.class);
Root<Box> box= q.from(Box.class);
Join<Box, Item> order = box.join(Box_.item);
q.where(cb.equal(cb.treat(order, SpecialItem.class).get(SpecialItem_.specialAttr), "searchValue");
q.select(Box);
If using JPA 2.1 you might use
"SELECT b FROM Box b WHERE TREAT(b.item as SpecialItem).specialAttr = :specialAttr"
or
CriteriaQuery<Box> q = cb.createQuery(Box.class);
Root<Box> box= q.from(Box.class);
Join<Box, Item > order = box.join("item");
q.where(cb.equal(cb.treat(order, SpecialItem.class).get("specialAttr"),
qb.parameter(String.class, "specialAttr")));
q.select(Box);