我正在尝试实现类似:
从Thread中选择线程where(从Thread中选择Sum(thread.emails)) 是等于?
我怎么能用Criteria + JPA来表达它?
提前致谢
答案 0 :(得分: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));