如何在jpa中过滤连接的实体

8ehkhllq  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(334)

我在下面展示了这个查询,我只想检索一些由属性名过滤掉的tproducts(比如哪个是活动的,哪个不是布尔值),我该怎么做呢?有人能帮忙吗?

value = "SELECT DISTINCT(t) FROM Trfi t " +
            "LEFT JOIN FETCH t.trfiProductCollection tProducts " +
            "LEFT JOIN FETCH tProducts.productModel pModel " +
            "LEFT JOIN FETCH t.trfiPaymentCollection tPayment " +
            "WHERE t.sedId IN (:sessionIds) ",
        countQuery = "SELECT COUNT (DISTINCT t) FROM Trfi t " +
            "JOIN t.trfiProductCollection tProducts " +
            "JOIN tProducts.productModel pModel " +
            "JOIN pModel.provider provider " +
            "JOIN t.trfiPaymentCollection tPayment " +
            "WHERE t.sedId IN (:sessionIds) "
    )
    List<Trfi> getTrfiListBySessionsId(@Param("sessionIds") List<Integer> sessionIds);
mefy6pfw

mefy6pfw1#

这对你不管用吗?

value = "SELECT DISTINCT(t) FROM Trfi t " +
        "LEFT JOIN FETCH t.trfiProductCollection tProducts " +
        "LEFT JOIN FETCH tProducts.productModel pModel " +
        "LEFT JOIN FETCH t.trfiPaymentCollection tPayment " +
        "WHERE t.sedId IN (:sessionIds) and tProducts.active = :active",
    countQuery = "SELECT COUNT (DISTINCT t) FROM Trfi t " +
        "JOIN t.trfiProductCollection tProducts " +
        "JOIN tProducts.productModel pModel " +
        "JOIN pModel.provider provider " +
        "JOIN t.trfiPaymentCollection tPayment " +
        "WHERE t.sedId IN (:sessionIds) and tProducts.active = :active"
)
List<Trfi> getTrfiListBySessionsId(@Param("sessionIds") List<Integer> sessionIds, @Param("sessionIds") boolean active);

相关问题