i use an extended Datatable with all kind of functions you implemented such as: paging, sorting, order-able columns, selection etc. . I used your demo Example of JPA Paging to build it ontop of a database.
if you looked the example of JPA padding you should realize that querying database is completelly depends on your code. We can't know if the data need or not need to be fetched. But your custom model defines that.
Unfortunatelly we simplified example from 3.3.x in 4.x demo. If you will look to 3.3.x demo - pay your attention that we declaring simple caches there. And the rule in our simple example is pretty straightforward if page, filtering or sorting is changed - build new query and call db for data. In your case the rules could be improved as you need.
I used similar approach and created next code: