title: Spring Data JPA Java - get Last 10 records from query
body: <p>Is there a way to retrieve the last X number of results from a query? </p>
  
  <p>For example - If want the first ten results, I see that example here works: <a href="https://stackoverflow.com/questions/9314078/setmaxresults-for-spring-data-jpa-annotation">setMaxResults for Spring-Data-JPA annotation?</a></p>
  
  <pre><code> public interface UserRepository extends Repository&lt;User, Long&gt; {
  
         List&lt;User&gt; findByUsername(String username, Pageable pageable);
   }
   //and then I could call it like this
   Pageable topTen = new PageRequest(0, 10);
   List&lt;User&gt; result = repository.findByUsername("Matthews", topTen);
  </code></pre>
  
  <p>But how do I get the LAST ten records? </p>
  
  <p>The only way I could think of doing it would be to flip the order in the query (findByUsernameDesc, assuming original results were ascending) and then iterate through the list backwards so I can process it in the order I wanted (ascending). </p>
  
  <p>That seems like an ugly way to do it. Is there a way to have the query give me the last X results in the order I want?</p>