Hello,
I'm using MS SQL server 2008.
I'm trying to modify a table with millions of rows of data using ScrollableResults. With a "regular" session.
The problem is that doing a flush ends with a out of memory error, even when I do the flush after changing the first row.
From the network activity, it seems that my application starts to download data while the flush() is executing.
If I don't change any data and just scroll through the rows, the problem does not occur (probably due to the fact, that there is nothing to flush). Memory usage stays low.
Using a StatelessSession seems to also fix the problem, allowing me to change data. Why is flushing downloading all this data, is there a setting or a bug I should know about?
Code:
ScrollableResults results = session.createQuery("SELECT user FROM User user")
.setReadOnly(false).setCacheable(false).scroll(ScrollMode.FORWARD_ONLY);
while (results.next()) {
User user = (User)results.get()[0];
user.setComment("Testing");
session.flush();
session.clear();
}
the last line in the log is
DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
edit: it seems that changing the ScrollMode.FORWARD_ONLY TO ScrollMode.SCROLL_SENSITIVE OR ScrollMode.SCROLL_INSENSITIVE did the trick and now it does not hang on flushing.
From debugging I can see that the select query that hibernate does in the 2 modes takes much longer to complete.
I still don't understand why it behaves like this and can't find a decent description of the varios scrollmodes. (SCROLL_INSENSITIVE scrolls a snapshot?)