Hibernate: @ManyToOne is EAGER by default, and that is usually wrong

JPA defaults @ManyToOne and @OneToOne to EAGER, so loading one entity silently drags its parents along.

Code
@Entity
class OrderItem {
    @ManyToOne(fetch = FetchType.LAZY)   // ALWAYS say this
    private Order order;

    @ManyToOne                            // defaults to EAGER
    private Product product;
}
Output
With the default: selecting 100 items also selects 100 products,
even if you only wanted the item quantities.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11