How to perform a join fetch in JPA Criteria without unchecked casting?
问题 I need to do a JOIN FETCH in JPA Criteria using a static metamodel, however I'm at a loss on how to do it without getting an unchecked exception warning. Suppose we have a Thing entity with a lazily-initialized Other entity inside it. I want to retrieve Things with fetched Others, where other.someField="someValue". This is roughly how I would do it: public List<Thing> getThings() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Thing> cq = cb.createQuery(Thing.class); Root root =