• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want clarification for some of the methods of Criteria class of org.hibernate

 
Tapan Maru
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

SQL has following kind of syntax:

select * from table_name limit 1,10;

where table_name is any table of database:

it fetches only first 10 records.

i am using criteria queries for querying database. for above operation i have found out following 3 methods.

1) setFirstResult(int i)
2) setMaxResults(int i)
3) setFetchSize(int i)

i know what first two methods are doing but has doubt about the third. suppose my select query returns 50 records and i want to show only 10 records per page, can i use like following?

setFirstResult(1);
setMaxResults(50);
setFetchSize(10);

please give any other methods, if available in API.

Thanks
 
Reehan Lalkhanwar
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setFirstResult - Set the first result to be retrieved.
setFetchSize - Set a fetch size for the underlying JDBC query.
setMaxResults - Set a limit upon the number of objects to be retrieved.

setFetchSize doesn't work and I think Hibernate guys are working on it.
setMaxResults first fetches the data from DB and then limits the objects.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!