JPA defaults @ManyToOne and @OneToOne to EAGER, so loading one entity silently drags its parents along.
@Entity
class OrderItem {
@ManyToOne(fetch = FetchType.LAZY) // ALWAYS say this
private Order order;
@ManyToOne // defaults to EAGER
private Product product;
}
With the default: selecting 100 items also selects 100 products,
even if you only wanted the item quantities.
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