CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2021

    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!

    Last edited by 2kaud; March 19th, 2021 at 03:18 AM. Reason: Link removed

  2. #2
    Join Date
    Feb 2017

    Re: N+1 SELECT problem in Hibernate

    Here's someone who claims to have a solution,

    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.
    Last edited by wolle; March 8th, 2021 at 12:27 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width