Sunday, September 28, 2014

How to Hibernate Using Scroll in Java

How to Hibernate Using Scroll in Java

Instructions

    1

    Determine the parameters of your search so that you know exactly what you're looking for in your search query. The reason for this is simple. If you try to use the "ScrollableResults" command to try to find your data, the end result will be that your query will lead to your program trying to read each row of data. This could literally result in the computer trying to load millions of rows of data, which takes significant RAM or Random Access Memory, thereby slowing your entire system down until the search has finished.

    2

    Begin your query by entering the proper Java command: "Session.createQuery()." This command will indicate you're beginning your search for the data you want to scroll for. The "setMaxResults()" and "setFirstResult()" commands allow you to determine the page of your query. Other types of commands can also be used to limit your search results and speed up the process.

    3

    Complete your query by entering the "scroll()" command into the query instructions. The "scroll()" command will begin the search according to whatever specifications you entered as you began the query. You can execute the query again with different parameters, but you'll have to wait until the first query has completed.

    4

    Remove objects from your session, especially when working on multiple queries. This can be done by adding the "evict()" command string. This command is designed to keep you from running out of memory, which you can do by using the scroll function when you conduct multiple search queries back to back.



No comments:

Post a Comment