This is a problem similar to: HQL - row identifier for pagination
I\'m trying to implement pagination using HQL. I have a PostgreSQL database.
int el
i'm using this solution:
/**
* @param limitPerPage
* @param page
* @return
*/
public List searchByPage(int limitPerPage, int page, String entity) {
String sql = "SELECT t FROM " + entity + " t";
Query query = em.createQuery(sql)
.setFirstResult(calculateOffset(page, limitPerPage))
.setMaxResults(limitPerPage);
return query.getResultList();
}
/**
* @param page
* @return
*/
private int calculateOffset(int page, int limit) {
return ((limit * page) - limit);
}
Welcome.