Introduction In this article, I’m going to explain what the N+1 query problem is when using JPA and Hibernate and what’s the best way to fix it. The N+1 query problem is not specific to JPA and Hibernate, as you can face this issue even if you are using other data access technologies.
Introduction Hibernate fetching strategies can really make a difference between an application that barely crawls and a highly responsive one. In this post, I’ll explain why you should prefer query-based fetching instead of global fetch plans. Fetching 101 Hibernate defines four association retrieving strategies: Fetching Strategy Description Join The association is OUTER JOINED in the original SELECT statement Select An additional SELECT statement is used to retrieve the associated entity(entities) Subselect An additional SELECT statement is used to retrieve the whole associated collection. This mode is meant for to-many associations Batch An… Read More