문제

How would I translate this JPQL query into Criteria API?

select count(p) from Person p join p.glanceList g where p.duration < 1000 and g
.duration < 1000
도움이 되었습니까?

해결책

Try this one.

CriteriaQuery<Long> q = cb.createQuery(Long.class);
Root<Person> person = q.from(Person.class);
Join<Person,Glance> glance = person.join("glanceList", JoinType.INNER);
q.select(cb.count(person))
.where(cb.lt(person.get("duration"), 1000), cb.lt(glance.get("duration"), 1000));

Assuming Glance is the class of the entity in the join.

And

CriteriaBuilder cb = em.getCriteriaBuilder();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top