How to implement Hibernate Pagination using the cursor (so that the results remain unchanged despite adding new data to the table on which the page is called)?

Is there a way to maintain a database cursor using hibernate between web requests? Basically, I am trying to implement pagination, but the data that is exposed is constantly changing (i.e. new entries are added to the database). We are trying to configure it in such a way that when you perform your initial search (returning a maximum of 5000 results) and you look at the results, the same records are always displayed on one page (i.e., we do not constantly execute the query each time we click on next and previous page buttons). The way we are currently implementing this is to simply select 5,000 (at most) primary keys from the table in which we place the pages, store these keys in memory, and then simply use 20 primary keys at a time to get them data from the databaseHowever, we want to get rid of the need to store these keys in memory and would prefer a database cursor, which we just keep going back and forth and back and forth to create pages.

I tried to do this with Hibernate ScrollableResults, but found that I could not call methods like next () and previous () that threw an exception if you were using another web request / hibernation session (there is nothing surprising here). Is there a way to associate a ScrollableResults object with a session, just as you would re-bind a single database object to make it persistent? Are there any other approaches to implementing this data paging with sequential paging results without caching primary keys?

+3
source share
1 answer

, . , OpenSessionInView , , HibernateSession , , -.

, Spring WebFlow, , . , , - Hibernate " -". , , , , -, , . (, .)

+2

Source: https://habr.com/ru/post/1744006/


All Articles