title: In back end (java spring boot) sorting, how to sort with Alias name using pageable? Without parent table as prefix
body: <p>I am using backend pagination and sorting with java spring boot <code>pageable</code>. While passing sort field as <code>usercount</code> (This gives count of <code>user_role_mapping</code>), Java triggering an error <strong>column f.usercount does not exist</strong> .
  Actually <code>usercount</code> not a column it's an Alias name.</p>
  <p>How to sort using <strong>usercount</strong> as Alies name without <strong>f.</strong> as prefix?</p>
  <p>API URL:</p>
  <pre><code>http://localhost:8080/facility/list?pageNumber=0&amp;pageSize=10&amp;sortBy=usercount&amp;sortType=asc
  </code></pre>
  <p>Default sortBy &amp; sortType are <strong>id</strong> and <strong>desc</strong> respectively in controller layer.</p>
  <p>Java Code give below:</p>
  <pre><code>Pageable pageable = PageRequest.of(pageNumber, pageSize, Sort.by(sortBy).descending());
  if (sortType.equalsIgnoreCase(&quot;asc&quot;)) {
      pageable = PageRequest.of(pageNumber, pageSize, Sort.by(sortBy).ascending());
  }
  Page&lt;FacilityProjection&gt; facilityList = facilityRepository.facilityListing(12,pageable);
  </code></pre>
  <p>Postgres sql Hibernate query for listing facility details along with user count based on role id, given below:</p>
  <pre><code>@Query(nativeQuery = true, value = &quot; Select f.name as facilityname,f.id as facilityid,count(urm.id) as usercount 
   from facility f
   join user u on f.user_id=u.id 
   join user_role_mapping urm on u.id = urm.user_id 
   where urm.role_id=:roleId &quot;)
  Page&lt;FacilityProjection&gt; facilityListing(@Param(&quot;roleId&quot;) Long roleId,Pageable pageable);
  </code></pre>