Questions et réponses d'entretien les plus demandées et tests en ligne
Plateforme d'apprentissage pour la preparation aux entretiens, les tests en ligne, les tutoriels et la pratique en direct

Developpez vos competences grace a des parcours cibles, des tests blancs et un contenu pret pour l'entretien.

WithoutBook rassemble des questions d'entretien par sujet, des tests pratiques en ligne, des tutoriels et des guides de comparaison dans un espace d'apprentissage reactif.

Preparation a l'entretien

Without Book Poser une question

Review the question and existing answers carefully before replying. The best answers explain the reasoning, steps, and tradeoffs so other learners can benefit too.

Votre question. Difference between Eager loading and Lazy Loading in Hibernate.

- Please explain with difference between Eager loading and lazy loading and in which situation which should be used.

Publie le Jul 23, 2014 Publie par Ruby Singh
Reponse. Sometimes you have two entities and there\'s a relationship between them. For example, you might have an entity called Organization and another entity called Employee.

The Organization entity might have some basic properties such as id, name, address, etc. as well as a property called students:

public class Organization {
private String id;
private String name;
private String address;
private List<employee> employees;

// setters and getters
}
Now when you load a Organization from the database, JPA loads its id, name, and address fields for you. But you have two options for employees: to load it together with the rest of the fields (i.e. eagerly) or to load it on-demand (i.e. lazily) when you call the Organization\'s getEmployees() method.

When a organization has many employees it is not efficient to load all of its employees with it when they are not needed. So in suchlike cases, you can declare that you want employees to be loaded when they are actually needed. This is called lazy loading.

Any time you see a @OneToOne, @OneToMany or @ManyToMany annotations, you’ve got a relationship. What’s important to note is that the fetch type should be specified within those annotations, if you don’t specify one then it defaults to FetchType.LAZY.
Publie le Jul 28, 2014 Publie par Arindam Ghosh

Saisissez votre reponse

Nom
Adresse e-mail
Reponse
Verification de securite
Resolvez ceci pour continuer : 2 + 8 = ?
Copyright © 2026, WithoutBook.