The best way to use JOIN FETCH and Pagination with Spring
Introduction In this article, we are going to see how we can use the JOIN FETCH clause when fetching a child collection eagerly while also limiting the number of parent records using pagination in a Spring Data JPA application. I decided to write this article because the most common solution used in many projects turns out to be extremely inefficient.
How to detect HHH000104 issues with hibernate.query.fail_on_pagination_over_collection_fetch
Introduction Recently, I noticed the hibernate.query.fail_on_pagination_over_collection_fetch configuration property that was introduced in Hibernate 5.2, and I had absolutely no idea it can be used to prevent the HHH000104 Hibernate issues. As previously explained, if you want to overcome the “HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!” issue, you have to either use 2 queries or a window function to fetch and limit the number of parent records while making sure you always fetch all their associated child entities. Even if the HHH000104 issue is logged as a warning message, it… Read More
The best way to fix the Hibernate “firstResult/maxResults specified with collection fetch; applying in memory!” warning message
Introduction If you’ve been using Hibernate long enough, then you surely must have seen this WARN log message when doing pagination while join-fetching multiple entities. HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! In this article, I’m going to show two ways you can to fix this issue.