Quote:
Im not clear how the method query.setFetchSize(int value) works.Does this method setFetchSize(int value) limits the number of records to be fetched (equal to the argument passed) from DB . To be more specific what is the difference between the two method
Method setMaxResults(int max) specifies the upper limit on how many rows will your query EVER fetch. For example, if your query could fetch 10,000 rows, and you specify setMaxResults(10), you will get 10 results, period - asking for row 11 will fail.
Method setFetchSize(int value) is a 'hint' to the driver, telling it how many rows it should fetch when it delivered the last row in it's buffer, and your code is asking for more.
For example, if your query could fect 10,000 rows, and you did NOT specify setMaxresult(10), the driver will fetch only setFetchSize() rows, and as your application retrieves those rows, when the first 'chunk' is used up, the driver will go to the database for the next one.
This avoids loading all 10,000 (or more:-) rows at once. However, this is an optimization hint, I remember (long ago) a MySQL driver loading 100,000 rows into memory in one 'chunk'... took a while to run out of memory. Loading more rows in a 'chunk' saves server roundtrips, loading too many rows ... takes up memory.
Plase, rate the posting (if it helped).
Martin.