一种解决方案是避免使用“ join”功能,而是执行完全交叉联接:
EntityManager em = getEntityManager();CriteriaBuilder cb = em.getCriteriaBuilder();CriteriaQuery<LoginNotification> query = cb.createQuery(LoginNotification.class);Root<LoginNotification> notfRoot = query.from(LoginNotification.class);Root<LoginEvent> eventRoot = query.from(LoginEvent.class);...query.where(cb.equals(notfRoot.get(Notification_.event), eventRoot.get(Event_.id)), ...(other criteria));
我认为一个不错的查询优化器应该做的简短,但是如果有人对这种方法的效率有任何见识,我将很乐意听到!



