N+1 SELECT problem in Hibernate
Hello, Newbie exploring Hibernate. I was wondering if there are any detailed walkaround for the above problem. I found it on the [Link removed] that the below process would give us a solution. Wondering if there are any other solutions!
Pre-fetch the records in batches which helps us to reduce the problem of N+1 to (N/K) + 1 where K refers to the size of the batch.
Subselect the fetching strategy
As last resort, try to avoid or disable lazy loading altogether.
Also, I also checked it in Stackoverflow. Felt it's a bit complicated!
TIA!!
Re: N+1 SELECT problem in Hibernate
Here's someone who claims to have a solution,
https://www.sipios.com/blog-tech/eli...plus-1-queries
I haven't heard about this problem before. But if it's a common inefficiency, why isn't it automatically optimized away by the query system? Or at least marked with a warning. In a declarative system, the programmer is supposed to express what to do, and the system is responsible for how to do it. If the system doesn't do its part efficiently, the whole idea fails, and the programmer resorts to writing procedural code. This seems to be the only existing "solution" to the N+1 SELECT problem.