0
如何將此JPQL查詢轉換爲Criteria API?JPA Criteria API加入
select count(p) from Person p join p.glanceList g where p.duration < 1000 and g
.duration < 1000
如何將此JPQL查詢轉換爲Criteria API?JPA Criteria API加入
select count(p) from Person p join p.glanceList g where p.duration < 1000 and g
.duration < 1000
試試這個。
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();