Lazy fetching (or initialization) is the opposite of eager fetching. Lazy fetching, the default in hibernate, means that when a record is loaded from the database, the one-to-many relationship child rows are not loaded. E.g.
@Entity
@Table(name = "COMPANY")
public class Company {
...
@OneToMany(fetch = FetchType.LAZY)
private Set<Employee> employees = new HashSet<Employee>();
requesting a company record will not return (set) Employees, who will have to be requested in another query.
Advantages
- performance. Employees are only loaded when needed (and requested). Benefit on CPU, memory, bandwidth... (both Java side and SQL server side).
Drawbacks
- when Employees are also needed, a separated query has to be performed.
Note that the query on Employees has to be performed during the same session (or the famous LazyInitializationException will be unwelcome).
This page holds interesting information.