가장 많이 묻는 면접 질문과 답변 & 온라인 테스트
면접 준비, 온라인 테스트, 튜토리얼, 라이브 연습을 위한 학습 플랫폼

집중 학습 경로, 모의고사, 면접 준비 콘텐츠로 실력을 키우세요.

WithoutBook은 주제별 면접 질문, 온라인 연습 테스트, 튜토리얼, 비교 가이드를 하나의 반응형 학습 공간으로 제공합니다.

Prepare Interview

모의 시험

홈페이지로 설정

이 페이지 북마크

이메일 주소 구독

Without Book 질문하기

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

작성일 Jul 23, 2014 작성자 Ruby Singh
답변. 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, youve got a relationship. Whats important to note is that the fetch type should be specified within those annotations, if you dont specify one then it defaults to FetchType.LAZY.
작성일 Jul 28, 2014 작성자 Arindam Ghosh

답변 입력

이름
이메일 주소
답변
보안 확인
계속하려면 풀어주세요: 9 + 9 = ?
Copyright © 2026, WithoutBook.