Spring-Data FETCH JOIN with Paging is not working

前端 未结 5 1748
野性不改
野性不改 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:03

    The easiest way is to use the countQuery attribute of the the @Query annotation to provide a custom query to be used.

    @Query(value = "SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments …",
           countQuery = "select count(v) from VisitEntity v where …")
    List getVenueVisits(@Param("venueId") long venueId, …);
    

提交回复
热议问题