如何将此JPQL查询转换为Criteria API?
select count(p) from Person p join p.glanceList g where p.duration < 1000 and g
.duration < 1000
答案 0 :(得分:3)
试试这个。
CriteriaQuery<Long> q = cb.createQuery(Long.class);
Root<Person> person = q.from(Person.class);
Join<Person,Glance> glance = order.join("glanceList", JoinType.INNER);
q.select(cb.count(person))
.where(cb.lt(person.get("duration"), 1000), cb.lt(glance.get("duration"), 1000));
假设Glance
是联接中实体的类。
并且
CriteriaBuilder cb = em.getCriteriaBuilder();