Hi,
Few days ago I was writing some code to iterate over quite a large dataset. Fitting those data in memory was quite a challenge even with 3GB heap space. So I did paging using two loops.
for (int page=0; page < resultCount; page+=pageSize) { Query q = em.createQuery("query"); for (Tuple t : q.setFirstResult(page).setMaxResults(pageSize).getResultList()) { // work with fetched data } em.clear(); }
I'll be using this with data streaming with REST and Jersey. So, my question is - is there a better way to do such thing with ODB? In PostgreSQL for example I can use cursors. With some JDBC drivers there is a hint, that driver should fetch data in packages of given size until whole result set is iterated.
What I'm thinking about is some kind of streaming of result set from database without building whole object graph representing fetched data in application memory.