title: Hibernate If the result of 'left join fetch' of @Manytoone is null, select it again
body: <p>I have tried many.
  But the cause could not be found.
  I need your help</p>
  
  <p><strong>CardNews Entity</strong></p>
  
  <pre><code>@Entity
  @Table(name = "card_news", schema = "pikeul", indexes = @Index(name = "IDX_CARD_NEWS_1", columnList = "user_seq, reg_date"))
  public class CardNews implements Serializable {
  
      private static final long serialVersionUID = 8912318097356401738L;
  
      @Id
      @Column(name = "card_seq", nullable = false)
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long cardSeq; 
  
      @Column(name = "user_seq", nullable = false)
      private long userSeq; 
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "user_seq", referencedColumnName = "user_seq", insertable = false, updatable = false, foreignKey = @ForeignKey(name = "none"))
      private User user;
  
      @Fetch(FetchMode.SELECT)
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumns(value = {
              @JoinColumn(name = "card_seq", referencedColumnName = "card_seq", insertable = false, updatable = false),
              @JoinColumn(name = "user_seq", referencedColumnName = "user_seq", insertable = false, updatable = false)
      }, foreignKey = @ForeignKey(name = "none"))
      private LikeCard likeCard = new LikeCard(); 
  
      // Getter &amp; Setter 
  }
  </code></pre>
  
  <p><strong>CardLike Entity</strong></p>
  
  <pre><code>@Entity
  @Table(name = "card_like", schema = "pikeul")
  public class LikeCard implements Serializable {
  
      @EmbeddedId
      private LikeCardPk pk;
  
      public LikeCard(){
          this.pk = new LikeCardPk(0, 0);
      }
  
      public LikeCard(LikeCardPk pk) {
          this.pk = pk;
      }
  
      public LikeCardPk getPk() {
          return pk;
      }
  
      public void setPk(LikeCardPk pk) {
          this.pk = pk;
      }
  
  
  }
  </code></pre>
  
  <p><strong>Spring Data JPA Query Case-1</strong></p>
  
  <pre><code>@EntityGraph(attributePaths = {"user", "likeCard"})
      @Query( "SELECT card  FROM CardNews card " +
              "JOIN card.user user ON user.useYn = true " +
              "LEFT JOIN card.likeCard likeCard ON likeCard.pk.userSeq = ?#{principal.user.userSeq ?: '0'} " +
              "WHERE card.cardSeq = :cardSeq AND card.useYn = true")
  </code></pre>
  
  <p><strong>Spring Data JPA Query Case-2</strong></p>
  
  <pre><code>@Query( "SELECT card, user, likeCard FROM CardNews card " +
              "JOIN card.user user ON user.useYn = true " +
              "LEFT JOIN card.likeCard likeCard ON likeCard.pk.userSeq = ?#{principal.user.userSeq ?: '0'} " +
              "WHERE card.cardSeq = :cardSeq AND card.useYn = true")
  </code></pre>
  
  <p><strong>The problem is as follows. When inquiring CardLike Entity through ManyToOne in CardNews Entity, CardLike Entity exists or does not exist.</strong></p>
  
  <p>CardLike may be null when fetching data through left join fetch when executing Query for Case1 and Case2.</p>
  
  <p>Look at the log. </p>
  
  <pre><code>Hibernate: 
      select
          cardnews0_.card_seq as card_seq1_5_0_,
          user1_.user_seq as user_seq1_12_1_,
          likecard2_.card_seq as card_seq1_4_2_,
          likecard2_.user_seq as user_seq2_4_2_,
          cardnews0_.contents as contents2_5_0_,
          cardnews0_.game_type as game_typ3_5_0_,
          cardnews0_.hash_tag as hash_tag4_5_0_,
          cardnews0_.user_seq as user_seq8_5_0_,
          cardnews0_.like_count as like_cou5_5_0_,
          cardnews0_.reg_date as reg_date6_5_0_,
          cardnews0_.use_yn as use_yn7_5_0_,
          user1_.agree_date as agree_da2_12_1_,
          user1_.agree_yn as agree_yn3_12_1_,
          user1_.email as email4_12_1_,
          user1_.mod_date as mod_date5_12_1_,
          user1_.nickname as nickname6_12_1_,
          user1_.night_push_yn as night_pu7_12_1_,
          user1_.profile_image as profile_8_12_1_,
          user1_.provider as provider9_12_1_,
          user1_.provider_id as provide10_12_1_,
          user1_.push_date as push_da11_12_1_,
          user1_.push_yn as push_yn12_12_1_,
          user1_.reg_date as reg_dat13_12_1_,
          user1_.thumbnail_image as thumbna14_12_1_,
          user1_.use_yn as use_yn15_12_1_ 
      from
          card_news cardnews0_ 
      inner join
          enter_user user1_ 
              on cardnews0_.user_seq=user1_.user_seq 
              and (
                  user1_.use_yn='Y'
              ) 
      left outer join
          card_like likecard2_ 
              on cardnews0_.card_seq=likecard2_.card_seq 
              and cardnews0_.user_seq=likecard2_.user_seq 
              and (
                  likecard2_.user_seq=?
              ) 
      where
          cardnews0_.card_seq=? 
          and cardnews0_.use_yn='Y'
  
  
  
  Hibernate: 
      select
          likecard0_.card_seq as card_seq1_4_0_,
          likecard0_.user_seq as user_seq2_4_0_ 
      from
          card_like likecard0_ 
      where
          likecard0_.card_seq=? 
          and likecard0_.user_seq=?
  </code></pre>
  
  <p>As above, if data is retrieved through left join fetch but CardLike Entity does not exist, you can see the log to select again.</p>
  
  <p>If this is the result of the list, select 1 + N.</p>
  
  <p>I tried to downgrade but the result was the same</p>
  
  <p>The development environment is as follows
  Spring 5.0.4, Spring-Data-JPA 2.0.4, Hibernate 5.2.13</p>