CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2021
    Location
    India
    Posts
    5

    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!!
    Last edited by 2kaud; March 19th, 2021 at 03:18 AM. Reason: Link removed

  2. #2
    Join Date
    Feb 2017
    Posts
    677

    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.
    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

Featured