我是标准API的新手,请帮助我使用Spring的QueryDSL实现以下查询:
SELECT a from TABLE_A a
WHERE a.name IN (
SELECT DISTINCT b.name from TABLE_C c
INNER JOIN c.table_B b
WHERE c.id = b.id AND c.id = :cId
)
AND a.id = :aId
如何执行以下操作:
public class TableASpecifications {
public static Specification<TableA> workflow(Long aId, Long cId) {
return (aRoot, query, cb) -> {
Root<TableC> cRoot = query.from(TableC.class);
final Join<TableC, TableB> tableB = cRoot.join("c", JoinType.LEFT);
//PROBLEM how to get something like:
return aRoot.get(TableA_.id).equals(aId)
// PSEUDOCODE below
.and(aRoot.get(TableA_.id).in(tableB.get("name")))
}
}
}
P.S。 JPA不允许这种查询吗?我看过this answer,但可能已经过时了。