Grokbase Groups Cayenne dev May 2009

Setting fetchSize with postgres does make a difference, even in a simple
JDBC select.
If you consider the following code copy-pasted from my test case:

PreparedStatement stmt =
FROM itemdetails WHERE profileID= 10 ORDER BY longtailpos");

ResultSet set = stmt.executeQuery();

int i = 0;


It can iterates through approx 1'500'000 rows without any memory issues
(java process stays at approx 20mo while the loop executes). I can also see
that it takes no more than a few seconds before the first row is printed in
the output console, meaning that results are still being fetched from the DB
at the moment the resultset is accessed.

Now if I comment the line "stmt.setFetchSize(1000);" in the above code,
execution stops at "ResultSet set = stmt.executeQuery();" for approx 15
seconds and then an OutOfMemoryException is thrown from JDBC code. Also in
cayenne code, that would be before the resultset is even accessed (making
ResultIterator useless).

A similar problem is exposed here, with a sample stacktrace :

And the reason is detailed here :

Perhaps other drivers that automatically use server side cursors aren't
affected or just ignore this setting but I can say for sure that this
setting is necessary with postGres.

Andrey, you say you keep getting OutOfMemory exceptions no matter which
value you set. Do you get these exceptions while iterating through the
results or during the call to executeQuery?
If you get it while looping through the resultset, it could mean that
somehow the rows objects aren't garbage collected, it can happen with
cayenne version 2.0 due to the dataContext holding strong references to the
dataObjects. I didn't want to write a fix for v3 at first, but I realized
that in v2, I had to manually unregister the dataObjects from the context in
order to keep the memory usage in safe areas.

If I can be of any help, please ask.
Best regards...

View this message in context:
Sent from the Cayenne - Dev mailing list archive at

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 6 of 11 | next ›
Discussion Overview
groupdev @
postedMay 21, '09 at 12:59p
activeMay 25, '09 at 10:40a



site design / logo © 2022 Grokbase