我有以下实体结构:
class A {
int aId;
B b;
}
class B {
int bId;
C c;
}
class C {
List<B> bs;
int cId;
}
我必须使用spring-data-jpa规范编写以下SQL代码部分:
SELECT * FROM A WHERE ~~blahblahblah~~ AND **bId in (SELECT bs FROM C WHERE cId = myCId)**
我试着这样做:
Subquery<B> bSubquery = criteriaQuery.subquery(B.class);
Root<B> bRoot = bSubquery.from(B.class);
bSubquery.select(bRoot).where(criteriaBuilder.equal(bRoot.get(B.c).get(C.cId), myCId));
return criteriaBuilder.equal(root.get(A.b), root.in(bSubquery));
但它不起作用。我的错误在哪里?