带有连接的QueryDSL子查询

时间:2017-09-29 12:04:28

标签: sql spring-data-jpa hibernate-criteria querydsl criteria-api

我是标准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,但可能已经过时了。

0 个答案:

没有答案
相关问题