Spring-Data FETCH JOIN with Paging is not working

前端 未结 5 1737
野性不改
野性不改 2020-11-30 05:37

I am trying to use HQL fetching my entity along with sub-entities using JOIN FETCH, this is working fine if I want all the results but it is not the case if I want a Page

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 06:13

    You have to specify countQuery param for @Query and now you can use Page or List as return value.

    @Query(value = "SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and ...",
           countQuery = "SELECT count(v) FROM VisitEntity v LEFT JOIN v.comments WHERE v.venue.id = :venueId and ..." )
    public Page getVenueVisits(@Param("venueId") long venueId,...,
            Pageable pageable);
    

提交回复
热议问题