How to paginate a JPA Query
For all JPA query objects (except for native SQL queries), you would use pagination through the setMaxResults(int) and setFirstResult(int) methods. For instance: return em.createNamedQuery(“yourqueryname”, YourEntity.class) .setMaxResults(noOfRecords) .setFirstResult(pageIndex * noOfRecords) .getResultList(); JPA will perform the pagination for you. Named queries are just predefined and can be cached, while other types are dynamically created. So the choice … Read more