I have a table which contains 1000 records.
I needed to pull 100 records at a time so I used setFetchSize in the hibernate Criteria as below(Deal is the entity object)
List<Deal> dealList= sess.createCriteria(Deal.class).setFetchSize(100).list();
But, after the above query when I printed the dealList size as
System.out.println("no. of deals "+dealList.size());
it gave 1000 records not 100 records.
Did I miss anything?
You will need setMaxResults().
Fetch size is a JDBC optimisation and not a restriction on the query performed. See this thread for more info on
setFetchSize()andsetMaxSize(), and this thread for how the two can work together for you.