使用
in表达式时,您只能使用基本比较类型,因此您需要进行联接并比较基本类型的字段(在此我已经使用过
Integer id):
Root<Foo> foo = cq.from(Foo.class);Join<Foo, Bar> bar = foo.join(Foo_.bar);Parameterexpression<Collection> bars = cb.parameter(Collection.class);cq.where(bar.get(Bar_.id).in(bars));TypedQuery<Foo> tq = em.createQuery(cq);Collection<Integer> barsParameter = new ArrayList<Integer> ();barsParameter.add(1);List<Foo> resultList = tq.setParameter(bars, barsParameter).getResultList();



