The dataset I display using PageableListView can get very big and keeping the whole dataset as a model would be very inefficient. Is it possible to load for example only the set of IDs first and then load only the objects that are to be displayed on the current page? I use Wicket+Spring+Hibernate/JPA. Or is there a better approach to paging in this case?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The usual way to deal with that (at least for me) would be to perform:
- a first query to count the items and deduce the number of pages to display
- subsequent queries using
Query#setFirstResult(int)
andQuery#setMaxResults(int)
for each page.
In Wicket, JPA, GlassFish and Java Derby or MySQL, the author shows precisely how to implement this approach using Wicket and a DataView
instead of PageableListView
(sample code provided).