I have the following entity structure:
class A {
int aId;
B b;
}
class B {
int bId;
C c;
}
class C {
List<B> bs;
int cId;
}
I have to write the following part of SQL code using spring-data-jpa specifications:
SELECT * FROM A WHERE ~~blahblahblah~~ AND **bId in (SELECT bs FROM C WHERE cId = myCId)**
I tried to do like this:
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));
But it does't work. Where is my mistake?