Our persistence classes have a few PrevAndNext find methods. They are using Hibernate's scroll query, hibernate actually gets all the results that meet the where cause, then scroll it locally. For some huge result set, this can cause very heavy network traffic.
In our Blogs benchmark test, the findByGroupId PrevAndNext method causes a 50MB/s traffic from database under a heavy load.
This fix uses two selects to fetch the previous and next result individually, so it saves the network traffic significantly(From 50MB/s to 3MB/s).
It also saves a lot of gc, since most results from database will become garbage immediately.