0

I am trying to implement something like:

Select thread from Thread where(Select Sum(thread.emails) from Thread) is equals to ?

How could I imolement it with Criteria + JPA?

Thanks in advance

4

1 回答 1

1

CriteriaBuilder 中有一个 size() 方法来定义集合的大小。

CriteriaBuilder cb = em.getCriteriaBuilder(); //em is EntityManager
CriteriaQuery<Thread> cq = cb.createQuery(Thread.class);

Root<Thread> root = cq.from(Thread.class);
Expression<Collection<String>> emails = root.get("emails");
cq.where(cb.equal(cb.size(emails), PARAM));
于 2012-06-29T12:54:27.523 回答