How to get results from a fixed position in Hibernate Criteria Query
Points To Remember
- Offset may be required to do pagination or get the results after a particular result from the database.
- Using offset you can define the first result to be included in the result set from the database.
- You can use setFirstResult on the CriteriaQuery to set the first result that you want.
Using offset to get the results
SampleDAO.java
@SuppressWarnings("unchecked") public List<Person> getCategories(Integer offset){ return getSession() .createCriteria(Person.class) .setFirstResult(offset!=null?offset:0) .setMaxResults(10) .list(); }
No comments: