title: Spring data JpaRepository pagination and group by
body: <p>In my JpaRepository interface I got the following method that works fine:</p>
  
  <pre><code>Page&lt;PermissionRule&gt; findByOrganizationIdAndTypeStringAndObjectReferenceIgnoreCaseContaining(
          Long organizationId, String typeId, String searchTerm, Pageable pageable);
  </code></pre>
  
  <p>What I need is the same query with a group by object_reference.</p>
  
  <p>This is what I tried doing :
  EDIT</p>
  
  <pre><code>@Query(value = "SELECT object_reference, dst_type, other FROM permission_rule pr WHERE pr.organization_id = %?1% AND pr.dst_type_id = %?2% AND pr.object_reference LIKE %?3% GROUP BY object_reference", nativeQuery = true)
  Page&lt;PermissionRule&gt; getFunds(Long organizationId, String dstTypeId, String searchTerm, Pageable pageable);
  </code></pre>
  
  <p>but I get the following error </p>
  
  <blockquote>
    <p>InvalidJpaQueryMethodException: Cannot use native queries with dynamic sorting and/or pagination in method</p>
  </blockquote>
  
  <p>Also if it helps my entity column that I want to use in GROUP BY is </p>
  
  <pre><code>@Column(name = "object_reference", nullable = false)
  private String objectReference;
  </code></pre>
  
  <p>My question is whether there is an easier way to do it or I still need a custom query (do I need to move the custom query in the Entity maybe or use named query instead?) ?</p>