title: Hibernate FetchMode.JOIN with one to many mapping
body: <p>There are two entity InvoiceHeader and InvoiceDetail with one to many mapping as below.</p>
  <p><strong>InvoiceHeader</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;view_invoice_hdr&quot;)
  @IdClass(InvoiceHdrPK.class)
  @Getter
  @NoArgsConstructor
  @EqualsAndHashCode
  public class InvoiceHeader{
    
    ....
    
    @OneToMany(mappedBy = &quot;invoiceHeader&quot;, fetch = FetchType.EAGER)
    @Fetch(value = FetchMode.JOIN)
    private List&lt;InvoiceDetail&gt; items;
  } 
  
  </code></pre>
  <p><strong>InvoiceHdrPK</strong></p>
  <pre><code>@Getter
  @ToString
  @NoArgsConstructor
  @AllArgsConstructor
  @EqualsAndHashCode
  public class InvoiceHdrPK implements Serializable {
  
      private String invoiceNumber;
      private InvoiceSource invoiceSource;
      private InvoiceType invoiceType;
      private Long companyId;
      private Integer invoiceYear;
  }
  </code></pre>
  <p>Similarly <strong>InvoiceDetail</strong></p>
  <pre><code>@Entity
  @Table(name = &quot;view_inv_dtl&quot;)
  @IdClass(InvoiceDetailPK.class)
  @Getter
  @NoArgsConstructor
  @EqualsAndHashCode
  public class InvoiceDetail{
    
    ....
    
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumns(value = {
              @JoinColumn(name = &quot;invoice_number&quot;, referencedColumnName = &quot;invoice_number&quot;, insertable = false, updatable = false),
              @JoinColumn(name = &quot;invoice_source&quot;, referencedColumnName = &quot;invoice_source&quot;, insertable = false, updatable = false),
              @JoinColumn(name = &quot;invoice_type&quot;, referencedColumnName = &quot;invoice_type&quot;, insertable = false, updatable = false),
              @JoinColumn(name = &quot;company_id&quot;, referencedColumnName = &quot;company_id&quot;, insertable = false, updatable = false),
              @JoinColumn(name = &quot;invoice_year&quot;, referencedColumnName = &quot;invoice_year&quot;, insertable = false, updatable = false),
      })
      private InvoiceHeader invoiceHeader;
  } 
  </code></pre>
  <p><strong>InvoiceDetailPK</strong></p>
  <pre><code>@Getter
  @ToString
  @NoArgsConstructor
  @AllArgsConstructor
  @EqualsAndHashCode
  public class InvoiceDetailPK implements Serializable {
  
      private String invoiceNumber;
      private InvoiceSource invoiceSource;
      private InvoiceType invoiceType;
      private BigDecimal rate;
      private Long itemNo;
      private Long companyId;
      private Integer invoiceYear;
  
  }
  </code></pre>
  <p>Both the entities are not an actual table in db level but are maintained as views.</p>
  <p><strong>Using JPA</strong> I am trying to fetch invoices using <strong>findAll(Specification, pageable)</strong> with <strong>FetchMode.JOIN</strong> to avoid <strong>n+1</strong> query problem.</p>
  <p>But getting exception</p>
  <pre><code>org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list...
  </code></pre>
  <p>So how can I fix this and what am I missing?</p>