title: How to sort a query result by their date (Jpa, Java Collections)
body: <pre><code>public List&lt;Movie&gt; findRange(int[] range) {
      CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
      cq.select(cq.from(Movie.class));
      Query q = em.createQuery(cq);
      q.setMaxResults(range[1] - range[0]);
      q.setFirstResult(range[0]);
      List&lt;Movie&gt; list1 = q.getResultList();
      Collections.sort(list1, new Comparator(){
             public int compare (Object o1, Object o2){
                 Movie p1 = (Movie)o1;
                 Movie p2 = (Movie)o2;
                 return p2.getDate().compareTo(p1.getDate());
             }
         });
      return list1;
  }
  </code></pre>
  
  <p>As it is now sorting works, but only with in the batch, <br>
  (batch = 4 movies) First one = last entered; Last one = fisrt entered. <br>
  But only compared with those in the batch not all of them as needed.</p>
  
  <p>Thank you very much for any help you can provide <br>
  best Regards<br>
  Ignacio   </p>