I have following classes:
@Embeddable Class A // (with field String x);
Class B // (with field @Embedded A a)
Class C // (with field @OneToOne B b);
I would like to create method getAllByXs(List<String> xs)
using criteria to get all C entries where c.b.a.x
is in xs
Typed query with content SELECT c FROM C c JOIN c.b b WHERE b.a.x IN :param
works fine. How to write same query using Criteria?
答案 0 :(得分:2)
基于标准的示例查询可能如下所示:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<C> cq = cb.createQuery(C.class);
Root<C> c = cq.from(C.class);
Join<C, B> b = c.join("b");
cq.select(c)
cq.where(b.get("a").get("x").in(cb.parameter(List.class, "param")));
List<C> = em.createQuery(cq)
.setParameter("param", Arrays.asList("foo", "bar", "baz"))
.getResultList();