I'm a fan of using lazy collections with my application, that way my UI component (In my case, a Tapestry table grid that handles paging automatically) can just re-query each time the page is displayed. Only the records displayed are actually loaded.
This approach only works well if the display set is small (say 25 or less) because each row displayed results in a trip back to the DB (unless the objects are cached). The single query to fetch the collection is fast because only ID's and Version numbers are involved. Note: You can't return lazy results from HQL - you have to use the Criteria API. (Which sucks, in my opinion! Hoping for this feature in H3.) A child collection can simply be mapped as lazy="true",
Another approach is to use a Query object and page through your results one at a time. You can do this using: Query.setMaxResults() and Query.setFirstResult(). The problem here is that you still have to run the query each time, but it limits the results. BTW, this is covered in the FAQ, which is worth reading and will allow you to take off your asbestos underwear when posting to this forum.
There are probably other approaches, but these have worked well for me.
|