Lazy loading

Lazy loading defers reading a relationship until first access, instead of loading it with the entity. It avoids unnecessary queries but requires the persistence context to still be open, otherwise LazyInitializationException. @ManyToOne and @OneToOne relationships are loaded eagerly by default, @OneToMany lazily.

Example

@OneToMany(fetch = FetchType.LAZY)
List<Commande> commandes;

Related concepts

The whole glossary