title: How to limit the max rows without Using Pageable for JPASpecificationsExecutor?
body: <p>I am trying to understand and figure out the solution for the following use case</p>
  
  <p>These are my entity classes</p>
  
  <p>User</p>
  
  <pre><code>@Entity
  @Table(name = "USER")
  public class User  {
    private UserID id;
    private Set&lt;UserAddress&gt; addresses = new HashSet&lt;UserAddress&gt;(0);
    @EmbeddedId
    @AttributeOverrides( {
          @AttributeOverride(name = "userId", column = @Column(name = "USER_ID", nullable = false, length = 32)),
          @AttributeOverride(name = "userType", column = @Column(name = "USER_TYPE", nullable = false, precision = 12, scale = 0)) })
    public User getId() {
       return this.id;
    }
    @OneToMany(fetch = FetchType.EAGER,  mappedBy = "user", cascade={CascadeType.ALL})    
    @BatchSize(size=50)
    public Set&lt;UserAddress&gt; getAddresses() {
      return this.addresses;
    }
    ........
  }
  </code></pre>
  
  <p>UserAddress</p>
  
  <pre><code>@Entity
  @Table(name = "USERADDRESS")
  public class UserAddress  {
    private UserID id;
    Private User user;
    private String address; 
    @EmbeddedId
    @AttributeOverrides( {
          @AttributeOverride(name = "userId", column = @Column(name = "USER_ID", nullable = false, length = 32)),
          @AttributeOverride(name = "userType", column = @Column(name = "USER_TYPE", nullable = false, precision = 12, scale = 0)) })
    public User getId() {
       return this.id;
    }
    @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumns( {
      @JoinColumn(name = "userId", referencedColumnName = "USER_ID", nullable = false, insertable=false, updatable=false),
      @JoinColumn(name = "userType", referencedColumnName = "USER_TYPE", nullable = false, insertable=false, updatable=false) })
    public User getUser() {
      return this.user;
    }
    ........
  }
  </code></pre>
  
  <p>UserId</p>
  
  <pre><code>@Embeddable
  public class UserId implements Serializable {
     private String userNo;
     private Long UserType;
     .......
     .......
  }
  </code></pre>
  
  <p>I have created a staticmetamodel class for User, UserID and UserAddress and created query based on Specifications. </p>
  
  <p>Metamodel class for User</p>
  
  <pre><code>@StaticMetamodel(User.class)
  public abstract class User_ {
  
    public static volatile SetAttribute&lt;User, UserAddress&gt; addresses;
    public static volatile SingularAttribute&lt;User, UserID&gt; id;
  }
  </code></pre>
  
  <p>Metamodel for UserId</p>
  
  <pre><code>@StaticMetamodel(UserID.class)
  public abstract class UserID_ {
     public static volatile SingularAttribute&lt;UserID, String&gt; userNo;
     public static volatile SingularAttribute&lt;UserID, Long&gt; UserType;
  }
  </code></pre>
  
  <p><strong>I am trying to retrieve maximum of 10 User objects ordered by UserType and searched based on userId. The query has to retrieve the UserAddresses as an eager fetch.</strong></p>
  
  <p>My Specification Object is</p>
  
  <p>UserSpecification</p>
  
  <pre><code>public class UserSpecifications {
     public static Specification&lt;User&gt; userNoIs(String userNo) {
        return (root, query, cb) -&gt; {
          root.fetch(User_.addresses);
          return cb.equal(root.get(User_.id).get(UserID_.userNo),userNo);
        };
     }
  }
  </code></pre>
  
  <p>DAO Function: </p>
  
  <pre><code> Sort sortInstructions = new Sort(Sort.Direction.DESC, "id.userNo");
   Pageable pageInfo = new PageRequest(0, maxCount, sortInstructions);
   Specifications&lt;User&gt; specifications = Specifications.where(userNoIs(input.getUserNo()));
   Page&lt;User&gt; responseList= userRepository.findAll(specifications,pageInfo);
  </code></pre>
  
  <p>I am getting the following exception when I run the above statement. </p>
  
  <pre><code>Caused by: 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=generatedAlias1,role=com.entity.User.addresses,tableName=USERADDRESS ,tableAlias=useraddress1_,origin=USER user0,columns={user0.USER_TYPE user0.USER_ID ,className=com.entity.UserAddress}}]
  </code></pre>
  
  <p>But apart from that I also need to understand how to limit the no of rows returned using Specification but without using Pageable . If I use Pageable, then a separate query will be fired to retrieve the count of rows and then actual query is being fired. My application is performance oriented, and I do not want to have any extra queries being fired. </p>
  
  <p>Is there any way where I can limit the no of rows without using Pageable, but using Specifications ?</p>