Reputation: 1178
I'm trying to fetch n rows at a time from a table, but I don't know how to proceed. I looked at both the Criteria api and the Restrictions api, but I haven't found anything like it. So, is it possible in Hibernate? Is it possible in MySQL at all?
The table has an ID, but is autogenerated from the database and it is not so reliable (I mean, there can be a lot of missing numbers from two successive IDs). Also, there is a data column, so I can surely order the results by this column in ascending/descending order.
Upvotes: 1
Views: 1012
Reputation: 2944
you can do with setFirstResult(setFirstRow) and setMaxResults(setNumberOfRecordsTofetchAtaTime) methods in Hibernate Criteria.
Example
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Example.class);
criteria.setFirstResult(setFirstRow);
criteria.setMaxResults(setNumberOfRecordsTofetchAtaTime);
List<Example> list=criteria.list();
Upvotes: 3