lazy loading
Loading related data from the database only when code first accesses it, instead of together with the object that refers to it.
In more detail
Lazy loading avoids fetching data nobody uses, but accessing a lazy relation after the transaction has ended fails, and touching one per row issues an extra query each time. Fetch what the response actually needs within the use case.
Related terms
- N+1 query problem — A performance bug where code runs one query for a list and then one more query per item, so N items cost N+1 queries.
- persistence context — The set of entities JPA is currently tracking in a unit of work, whose changes it writes to the database automatically.
- lazy evaluation — Postponing work until its result is actually needed, rather than doing it all in advance.
Taught in
- Persistence With JPA And Hibernate — Modern Java: Virtual Threads & High-Throughput Services
- Spring Data Repositories — Modern Java: Virtual Threads & High-Throughput Services