Easy learning with example program codes

n+1 problem in hibernate

Let us understand n+1 problem with a simple example. Suppose we have collection of students and every student have collection subjects. To get all students and all subjects per students we need to execute one query to fetch all students and n queries to fetch subjects of n number of students. At the last we need to execute n+1 queries.

In hibernate n+1 problem occurs in case of lazy loading.

Hibernate n+1 problem solution:
We can use eager loading but it may leads to the performance issues so we have to use BasicCollectionLoader to load all children at once, when needed.

Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki