From e0080a94b74542bce4254a84d81679070915dda5 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Fri, 2 Aug 2024 04:01:00 +0000 Subject: [PATCH] chore : using entitygraph instead of joins --- .../graphql/querydsl/repositories/PostRepository.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java index bbd10562d..18b55ead6 100644 --- a/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java +++ b/graphql/boot-graphql-querydsl/src/main/java/com/example/graphql/querydsl/repositories/PostRepository.java @@ -5,6 +5,7 @@ import com.querydsl.core.types.dsl.StringExpression; import com.querydsl.core.types.dsl.StringPath; import java.util.List; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -23,9 +24,8 @@ default void customize(QuerydslBindings bindings, QPost root) { bindings.excluding(root.id); } - @Query( - "select o from Post o left join fetch o.details pd left join fetch o.comments where pd.createdBy = :createdBy") - List findByDetails_CreatedByEqualsIgnoreCase(@Param("createdBy") String createdBy); + @EntityGraph(attributePaths = {"details", "comments"}) + List findByDetails_CreatedByEqualsIgnoreCase(String createdBy); @Query("select p from Post p left join fetch p.tags where p in :posts ORDER BY p.id") List findAllPostsWithTags(@Param("posts") List posts);