Multiple JOIN FETCH in one JPQL query

不想你离开。 提交于 2019-12-02 18:03:28

You can use a Child-Parent fetch strategy and recombine the entity tree from the result.

SELECT p 
FROM Post p 
JOIN FETCH p.topic t 
JOIN FETCH t.category c 
WHERE ...
wangf

Here is a working example of complex join and multiple consition:

    String query_findByProductDepartmentHospital = "select location from ProductInstallLocation location "
            + " join location.product prod " + " join location.department dep "
            + " join location.department.hospital hos " + " where  prod.name = :product "
            + " and dep.name.name = :department " + " and hos.name = :hospital ";

    @Query(query_findByProductDepartmentHospital)
    ProductInstallLocation findByProductDepartmentHospital(@Param("product") String productName,@Param("department") String departName, @Param("hospital") String hospitalName);
koly

A workaround is to use @Query and @EntityGraph together, like it mentioned here use @Query and @EntityGraph together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!