title: I have N+1 problem but fetch join seems dosen't work
body: <p>Relation of tables are</p>
  <pre><code>USER(N) - (1)Follow_Shop(1) - (N)Shop
  
  </code></pre>
  <p>and Follow_shop has PK of USER, SHOP AS FK</p>
  <p>So the Follow_SHOP columns are</p>
  <pre><code>id || user_id(PK of USER) || shop_id(PK of SHOP)
  
  </code></pre>
  <p>The result that I want to get is information of shop in shop table via follow_shop table</p>
  <p>So I try this query to get shop data</p>
  <pre><code>    @Query(&quot;SELECT distinct fs FROM FollowShop fs JOIN FETCH fs.shop JOIN FETCH fs.user WHERE fs.user.id=:userId &quot;)
      List&lt;FollowShop&gt; findMyFollowShopById(@Param(&quot;userId&quot;) Long Id);
  </code></pre>
  <p>Find shop_id with user_id in Follow_shop table and take info of shop with shop_id</p>
  <p>And to avoid N+1 Problem I use fetch join, but the hibernate query go out like this</p>
  <pre><code>2022-02-11 04:22:27.411 DEBUG 50469 --- [nio-8080-exec-2] org.hibernate.SQL                        : select user0_.id as id1_7_, user0_.created_at as created_2_7_, user0_.modified_at as modified3_7_, user0_.auth_provider as auth_pro4_7_, user0_.email as email5_7_, user0_.nickname as nickname6_7_, user0_.password as password7_7_, user0_.phone_number as phone_nu8_7_, user0_.profile_img as profile_9_7_, user0_.provider_id as provide10_7_, user0_.refresh_token as refresh11_7_ from users user0_ where user0_.email=?
  2022-02-11 04:22:27.422 DEBUG 50469 --- [nio-8080-exec-2] org.hibernate.SQL                        : select roles0_.user_id as user_id1_6_0_, roles0_.roles as roles2_6_0_ from user_roles roles0_ where roles0_.user_id=?
  2022-02-11 04:22:27.437 DEBUG 50469 --- [nio-8080-exec-2] org.hibernate.SQL                        : select user0_.id as id1_7_, user0_.created_at as created_2_7_, user0_.modified_at as modified3_7_, user0_.auth_provider as auth_pro4_7_, user0_.email as email5_7_, user0_.nickname as nickname6_7_, user0_.password as password7_7_, user0_.phone_number as phone_nu8_7_, user0_.profile_img as profile_9_7_, user0_.provider_id as provide10_7_, user0_.refresh_token as refresh11_7_ from users user0_ where user0_.email=?
  2022-02-11 04:22:27.439 DEBUG 50469 --- [nio-8080-exec-2] org.hibernate.SQL                        : select roles0_.user_id as user_id1_6_0_, roles0_.roles as roles2_6_0_ from user_roles roles0_ where roles0_.user_id=?
  2022-02-11 04:22:27.452 DEBUG 50469 --- [nio-8080-exec-2] org.hibernate.SQL                        : select user0_.id as id1_7_, user0_.created_at as created_2_7_, user0_.modified_at as modified3_7_, user0_.auth_provider as auth_pro4_7_, user0_.email as email5_7_, user0_.nickname as nickname6_7_, user0_.password as password7_7_, user0_.phone_number as phone_nu8_7_, user0_.profile_img as profile_9_7_, user0_.provider_id as provide10_7_, user0_.refresh_token as refresh11_7_ from users user0_ where user0_.email=?
  2022-02-11 04:22:27.454 DEBUG 50469 --- [nio-8080-exec-2] org.hibernate.SQL                        : select roles0_.user_id as user_id1_6_0_, roles0_.roles as roles2_6_0_ from user_roles roles0_ where roles0_.user_id=?
  2022-02-11 04:22:27.458 DEBUG 50469 --- [nio-8080-exec-2] org.hibernate.SQL                        : select distinct followshop0_.id as id1_2_0_, shop1_.id as id1_4_1_, user2_.id as id1_7_2_, followshop0_.shop_id as shop_id2_2_0_, followshop0_.user_id as user_id3_2_0_, shop1_.address as address2_4_1_, shop1_.bellscore as bellscor3_4_1_, shop1_.image as image4_4_1_, shop1_.latitude as latitude5_4_1_, shop1_.longitude as longitud6_4_1_, shop1_.name as name7_4_1_, shop1_.runtime as runtime8_4_1_, (select count(*) from follow_shop where follow_shop.shop_id=shop1_.id) as formula1_1_, user2_.created_at as created_2_7_2_, user2_.modified_at as modified3_7_2_, user2_.auth_provider as auth_pro4_7_2_, user2_.email as email5_7_2_, user2_.nickname as nickname6_7_2_, user2_.password as password7_7_2_, user2_.phone_number as phone_nu8_7_2_, user2_.profile_img as profile_9_7_2_, user2_.provider_id as provide10_7_2_, user2_.refresh_token as refresh11_7_2_ from follow_shop followshop0_ inner join shop shop1_ on followshop0_.shop_id=shop1_.id inner join users user2_ on followshop0_.user_id=user2_.id where followshop0_.user_id=?
  </code></pre>
  <p>As you know the &quot;SAME&quot; query goes out 3times!! I dont know why;
  And the query selects all USER entity field and try to take it.
  But actually I don't need USER info this time.
  And To avoid this n+1 problem I use &quot;Fetch Join&quot; on my query but it seems like, It dosen't work....
  Am I wrote wrong grammar?</p>
  <p>ADD extra info of my code</p>
  <p>service layer code</p>
  <pre><code>    @Transactional(readOnly = true)
      public List&lt;MyFollowShopResponse&gt; myFollowShop(User user) {
          List&lt;MyFollowShopResponse&gt; followShops = followShopRepository.findMyFollowShopById(user.getId()).stream()
                  .map(MyFollowShopResponse::from)
                  .collect(Collectors.toList());
          return followShops;
      }
  </code></pre>
  <p>Controller layer code</p>
  <pre><code>    @GetMapping(&quot;/follow/shop&quot;)
      public ResponseEntity&lt;?&gt; myFollowShopList(@RequireLogin User user) {
          List&lt;MyFollowShopResponse&gt; list = followService.myFollowShop(user);
          return ResponseEntity.status(HttpStatus.OK).body(list);
      }
  </code></pre>
  <p>MyFollowShopResponseDto</p>
  <pre><code>@Getter
  @NoArgsConstructor(access = AccessLevel.PROTECTED)
  @AllArgsConstructor
  public class MyFollowShopResponse {
  
      private Long shopId;
  
      private String shopName;
  
      private String profileImg;
  
      public static MyFollowShopResponse from(FollowShop followShop) {
          return new MyFollowShopResponse(followShop.getShop().getId(), followShop.getShop().getName(), followShop.getShop().getImage());
      }
  }
  </code></pre>
  <p>follow_shop db data -&gt; has 5 datas</p>
  <pre><code>id || user_id || shop_id
  -------------------------
  1  ||   1    ||    1
  2  ||   2    ||    1
  3  ||   3    ||    1
  4  ||   1    ||    1
  5  ||   4    ||    1
  </code></pre>
  <p>shop db -&gt; has 2 datas</p>
  <pre><code>id || name ......
  --------------------
  1 ||  dd
  2 ||  dddd
  </code></pre>
  <p>user db -&gt; has 4 datas</p>
  <pre><code>id || name || .......
  -----------------
  1
  2
  3
  4
  </code></pre>
  <p>matching data with user_id = 1 in follow_shop tables only two</p>
  <p>and postman came out same result which I expected.</p>
  <p>result of postman</p>
  <pre><code>[
      {
          &quot;shopId&quot;: 1,
          &quot;shopName&quot;: &quot;dd&quot;,
          &quot;profileImg&quot;: &quot;1&quot;
      },
      {
          &quot;shopId&quot;: 1,
          &quot;shopName&quot;: &quot;dd&quot;,
          &quot;profileImg&quot;: &quot;1&quot;
      }
  ]
  </code></pre>