Are there any means to work with long query results in Hibernate? What if I want to draw table with million of records and allow user to navigate over it?
The goal is not to transfer all data to client at the time and handle the current position.
Are there any means to work with long query results in Hibernate? What if I want to draw table with million of records and allow user to navigate over it?
The goal is not to transfer all data to client at the time and handle the current position.
You can use simple mechanism of
FirstResult
andMaxResults
in a Query object.Above will fetch
5
records from fifth record.You can use ScrollableResults but it will be slower compared to above one for large results.
You may try with Hibernate ScrollableResults, I quote:
To improve queries with large dataset, use a keyset pagination and avoid offset pagination if possible because using an offset needs to read all data while using a keyset pagination (filter) reduces the dataset (improvements can be significant).
Here is a good article https://use-the-index-luke.com/no-offset