-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: setFetchSize(int value)
PostPosted: Mon Jan 15, 2007 6:29 am 
Newbie

Joined: Mon Jan 15, 2007 6:17 am
Posts: 4
query.setFetchSize(int value) is not working as expected.

even though i specify the fetch size, in the above method the query is listing all the results that match the criteria irrespective of fetch size. i din't get exactly how that method is working. can any one of u help me in finding the solution

thnx


Top
 Profile  
 
 Post subject: hi
PostPosted: Mon Jan 15, 2007 6:37 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:25 am
Posts: 39
Location: India Hyderabad
hi,

setFetch.. method is used to get some records on specific time.
anyway it will bring all the records. but whtever the input you given
based on it, it will bring the set of records at time instead of bringing all the records at at time.

I mean if you give 15 to the method it wil bring 15 records and it wil keep it in memory.

- dat is the funda...

let me know if my understanding is wrong.

-----------------
dont forget to rate


Top
 Profile  
 
 Post subject: setFetchSize(int value)
PostPosted: Mon Jan 15, 2007 6:42 am 
Newbie

Joined: Mon Jan 15, 2007 6:17 am
Posts: 4
thts wt i wanna say if i specify 15 as the fetch size it is fetching more than 15 , to be more clear it is fetching all the records from DB taht match the search criteria. but my requirement is to fetch only 15 records, its not working in this way


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 15, 2007 1:09 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
May be I do not understand what are you trying to accomplish...
Quote:
The JDBC fetch size gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed


If you want to fetch a specific number of records, use
query.setMaxResults(15)

To start at certain offset (30), and bring in next 15 records, use
query.setFirstResult(30);
query.setMaxResults(15);

Do not forget to rate this posting (in case it helped).
Martin.


Top
 Profile  
 
 Post subject: setFetchSize(int value)
PostPosted: Tue Jan 16, 2007 12:22 am 
Newbie

Joined: Mon Jan 15, 2007 6:17 am
Posts: 4
thanx for ur reply, i already tried query.setMaxResults(int value) and
query.setFirstResult(int value), this is working fine as per the expectations. 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 methods

query.setMaxResults(int value ) and query.setFetchSize(int value). I once again thank for ur reply. Any help for this posting is greatly appreciated

thnx


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 9:12 pm 
Regular
Regular

Joined: Wed Dec 07, 2005 4:19 pm
Posts: 53
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.


Top
 Profile  
 
 Post subject: Re: setFetchSize(int value)
PostPosted: Sun Aug 07, 2011 6:12 am 
Pro
Pro

Joined: Mon Apr 16, 2007 8:10 am
Posts: 246
setFetchSize seems to be necessary at times to work around an issue

http://benjisimon.blogspot.com/2007/...fetchsize.html

Has any one additional comments on that ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.