История изменений
Исправление totik, (текущая версия) :
Вы не поняли проблему.
С другим методом, где нет фильтрации по member та же проблема:
@Query("SELECT new OrganizationCount(o, COUNT(sv)) " +
"FROM Organization o " +
"LEFT JOIN o.videos v " +
"LEFT JOIN v.shownVideos sv " +
"GROUP BY o " +
"ORDER BY o.title")
public List<OrganizationCount> organizationVideoShowCounts();
Hibernate: select organizati0_.id as col_0_0_, count(shownvideo3_.id) as col_1_0_ from Organization organizati0_ left outer join Video videos1_ on organizati0_.id=videos1_.customerOrganization_id left outer join Video video2_ on videos1_.id=video2_.id left outer join shown_video shownvideo3_ on video2_.id=shownvideo3_.video_id group by organizati0_.id order by organizati0_.title
Hibernate: select organizati0_.id as id1_3_0_, organizati0_.playlist_id as playlist3_3_0_, organizati0_.title as title2_3_0_, playlist1_.id as id1_5_1_, playlist1_.title as title2_5_1_ from Organization organizati0_ left outer join Playlist playlist1_ on organizati0_.playlist_id=playlist1_.id where organizati0_.id=?
Hibernate: select organizati0_.id as id1_3_0_, organizati0_.playlist_id as playlist3_3_0_, organizati0_.title as title2_3_0_, playlist1_.id as id1_5_1_, playlist1_.title as title2_5_1_ from Organization organizati0_ left outer join Playlist playlist1_ on organizati0_.playlist_id=playlist1_.id where organizati0_.id=?
По первому запросу извлекаются все данные для того, чтобы сконструировать и объекты сущности Organization и число shownVideo по каждому из них.
Но spring data несмотря на это по каждой записи все равно извлекает Organization отдельным запросом. Классическая проблема n+1. Но причины мне непонятны.
Исходная версия totik, :
Вы не поняли проблему.
С другим методом, где нет фильтрации по member та же проблема:
@Query("SELECT new com.helan.adkiosk.webserver.controllers.data.aggreate.OrganizationCount(o, COUNT(sv)) " +
"FROM Organization o " +
"LEFT JOIN o.videos v " +
"LEFT JOIN v.shownVideos sv " +
"GROUP BY o " +
"ORDER BY o.title")
public List<OrganizationCount> organizationVideoShowCounts();
Hibernate: select organizati0_.id as col_0_0_, count(shownvideo3_.id) as col_1_0_ from Organization organizati0_ left outer join Video videos1_ on organizati0_.id=videos1_.customerOrganization_id left outer join Video video2_ on videos1_.id=video2_.id left outer join shown_video shownvideo3_ on video2_.id=shownvideo3_.video_id group by organizati0_.id order by organizati0_.title
Hibernate: select organizati0_.id as id1_3_0_, organizati0_.playlist_id as playlist3_3_0_, organizati0_.title as title2_3_0_, playlist1_.id as id1_5_1_, playlist1_.title as title2_5_1_ from Organization organizati0_ left outer join Playlist playlist1_ on organizati0_.playlist_id=playlist1_.id where organizati0_.id=?
Hibernate: select organizati0_.id as id1_3_0_, organizati0_.playlist_id as playlist3_3_0_, organizati0_.title as title2_3_0_, playlist1_.id as id1_5_1_, playlist1_.title as title2_5_1_ from Organization organizati0_ left outer join Playlist playlist1_ on organizati0_.playlist_id=playlist1_.id where organizati0_.id=?
По первому запросу извлекаются все данные для того, чтобы сконструировать и объекты сущности Organization и число shownVideo по каждому из них.
Но spring data несмотря на это по каждой записи все равно извлекает Organization отдельным запросом. Классическая проблема n+1. Но причины мне непонятны.