Quick revision
The short answer
In JPA, @ManyToOne and @OneToOne default to EAGER, while @OneToMany and @ManyToMany default to LAZY. EAGER is a bad default because it cannot be switched off per query: every load of the entity, including JPQL queries, fetches the association, often with extra selects, and the eager graph grows as the model grows. The usual practice is to make every association LAZY and fetch what each use case needs with fetch joins, entity graphs or DTO queries.
What to remember
In this answer, we saw that @ManyToOne and @OneToOne default to EAGER and the collection associations to LAZY, that EAGER cannot be turned off per query and adds selects to JPQL queries, and that eager graphs grow as the model grows. The common convention is to make every association LAZY and define a fetch plan per use case with fetch joins, entity graphs or DTO queries.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
In JPA, @ManyToOne and @OneToOne default to EAGER, while @OneToMany and @ManyToMany default to LAZY. EAGER is a bad default because it cannot be switched off per query: every load of the entity, including JPQL queries, fetches the association, often with extra selects, and the eager graph grows as the model grows. The usual practice is to make every association LAZY and fetch what each use case needs with fetch joins, entity graphs or DTO queries.
Why this question is asked
Fetch types decide how much data comes back when we load one entity, so they quietly shape the performance of every screen in a JPA application. Most developers have seen a simple findAll run dozens of queries, and the cause is very often an EAGER association nobody chose on purpose, because it was the default. Interviewers ask this question to check that we know the defaults, and more importantly that we understand why experienced teams override them. In this answer, we will recap what fetch types mean, list the defaults and where they come from, see what EAGER does in practice, and set the convention most teams follow.
1A Quick Recap of Fetch Types
An association is a field on an entity that points to another entity or to a collection of them, such as Order.customer or Order.lines. The fetch type says when the associated data is loaded. EAGER means it must be loaded together with the owner, before we get the owner back. LAZY means Hibernate may wait and load it the first time our code touches it, using a proxy for a single entity or a wrapper collection for a list.
Strictly speaking, LAZY is a hint that the provider may ignore, while EAGER is a requirement that it must follow. That asymmetry is the root of the problem: we can always ask for more data in a specific query, but we can never ask for less than EAGER demands.
2The Defaults and Why They Differ
The defaults follow a simple idea from the original specification: a reference to a single entity is cheap, so load it eagerly, and a collection could be large, so load it lazily.
| Annotation | Default | Points to | Usual recommendation |
|---|---|---|---|
@ManyToOne | EAGER | one entity | set LAZY explicitly |
@OneToOne | EAGER | one entity | set LAZY, map from owning side |
@OneToMany | LAZY | collection | keep LAZY |
@ManyToMany | LAZY | collection | keep LAZY |
@ElementCollection | LAZY | collection of values | keep LAZY |
The reasoning about one row being cheap ignores what that row brings with it. A Customer may itself have an EAGER @ManyToOne to Region, Region to Country, Country to Currency, so loading one order pulls in a chain of entities, each with its own associations.
3What EAGER Does in Practice
With em.find(Order.class, 1L), Hibernate usually satisfies EAGER with a join in the same SQL statement, so it looks harmless in a quick test. Queries are different. A JPQL query is translated as written, and if it does not join the eager association, Hibernate must still honour EAGER, so after running the query it loads the association for the results with additional selects.
So the screen that wanted two columns from one table runs hundreds of queries. And the worst part is that we cannot tell this query to skip the customer. There is no per-query way to say LAZY for an association mapped EAGER; the mapping wins everywhere.
4Why EAGER Graphs Keep Growing
Over the years, entities gain associations. Each new @ManyToOne added without a fetch type is EAGER, and it is loaded everywhere the entity is loaded, including in code written years earlier that never needed it. A change made for one feature can slow down screens owned by other teams, and nobody connects the two because the change looked like a harmless new field.
With LAZY everywhere, the opposite holds: adding an association changes nothing for existing queries, and each use case asks for exactly what it needs.
5The Convention: LAZY Plus Explicit Fetch Plans
Most experienced teams set every association to LAZY and then decide, per use case, what to load. A fetch join loads the association in the same query, an entity graph does the same declaratively on a repository method, and a DTO query selects only the columns the screen shows.
Notice that each method states its own data needs. The cost is that we have to think about fetching for each use case, and code that touches a lazy association outside a transaction now fails with LazyInitializationException instead of silently working. That failure is useful: it points to a missing fetch plan, which is better than a hidden extra query.
6Follow-up questions
Is LAZY on @ManyToOne always honoured by Hibernate?
Yes for @ManyToOne, because the owner's row holds the foreign key, so Hibernate can create a proxy with that id. For the inverse side of a @OneToOne it is not, because Hibernate must query to know whether the related row exists, so that side is loaded anyway unless bytecode enhancement is used.
If EAGER is bad, why not make everything LAZY and enable open session in view?
Open session in view keeps the session open during view rendering, so lazy loads succeed there. That hides the missing fetch plan and moves the extra queries to the web layer, often as N+1 during JSON serialization. It is better to disable it and fetch what each use case needs inside the service.
Can I change an existing EAGER association to LAZY safely?
It changes behaviour for every caller, so first add statement count tests for the key use cases, then switch the association and add fetch joins or entity graphs where tests or LazyInitializationException show the data is needed. Do it one aggregate at a time, not across the whole model at once.
7Conclusion
In this answer, we saw that @ManyToOne and @OneToOne default to EAGER and the collection associations to LAZY, that EAGER cannot be turned off per query and adds selects to JPQL queries, and that eager graphs grow as the model grows. The common convention is to make every association LAZY and define a fetch plan per use case with fetch joins, entity graphs or DTO queries.
Open with
In JPA the single-valued associations, @ManyToOne and @OneToOne, default to EAGER, and the collections, @OneToMany and @ManyToMany, default to LAZY. The idea was that one row is cheap and a collection might be large.
Then, if they want more
The problem with EAGER is that it is a requirement the provider must honour everywhere, and there is no per-query way to switch it off.
With em.find, Hibernate usually adds a join, so it looks fine, but with a JPQL query that does not join the association, Hibernate runs the query and then loads the eager associations with extra selects, often one per distinct related entity.
And eager associations chain: customer to region to country, so one order can pull in a lot of data the screen never shows. Over the years, every new @ManyToOne added without a fetch type makes the graph bigger, and slows down code that never needed it.
So I set every association to LAZY explicitly, and for each use case I decide what to load: a join fetch, an entity graph on the repository method, or a DTO projection with only the needed columns.
If code then hits a LazyInitializationException, that tells me a fetch plan is missing, which I fix in the query rather than by going back to EAGER or enabling open session in view.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Data JPA reference, Hibernate ORM documentation, Spring Framework reference, Transaction management
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What are the default fetch types for @ManyToOne, @OneToOne, @OneToMany and @ManyToMany...": https://scrivio-interview-library.netlify.app/databases/jpa-performance/865a19fbad/