title: Spring-Data FETCH JOIN with Paging is not working
body: <p>I am trying to use HQL fetching my entity along with sub-entities using JOIN FETCH, this is working fine if I want all the results but it is not the case if I want a Page</p>
  
  <p>My entity is </p>
  
  <pre><code>@Entity
  @Data
  public class VisitEntity {
  
      @Id
      @Audited
      private long id;
  
      .
      .
      .   
  
      @OneToMany(cascade = CascadeType.ALL,)
      private List&lt;VisitCommentEntity&gt; comments;
  }
  </code></pre>
  
  <p>and because I have millions of visits I need to use Pageable and I want to Fetch the comments in a single database query like :</p>
  
  <pre><code>@Query("SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and ..." )
  public Page&lt;VisitEntity&gt; getVenueVisits(@Param("venueId") long venueId,...,
          Pageable pageable);
  </code></pre>
  
  <p>That HQL call throws the following exception:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=com.ro.lib.visit.entity.VisitEntity.comments,tableName=visitdb.visit_comment,tableAlias=comments1_,origin=visitdb.visit visitentit0_,columns={visitentit0_.visit_id ,className=com.ro.lib.visit.entity.VisitCommentEntity}}] [select count(v) FROM com.ro.lib.visit.entity.VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and (v.actualArrival &gt; :date or v.arrival &gt; :date)]
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1374)
  at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
  at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:309)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  </code></pre>
  
  <p>and once I remove the paging everything works fine</p>
  
  <pre><code>@Query("SELECT v FROM VisitEntity v LEFT JOIN FETCH v.comments WHERE v.venue.id = :venueId and  ..." )
  public List&lt;VisitEntity&gt; getVenueVisits(@Param("venueId") long venueId,...);
  </code></pre>
  
  <p>Obviously the problem is the count query from Spring-Data, but how can we fix it?</p>