Ir al contenido

Eager Fetch Type On Association (ARCH4060)

Esta página aún no está disponible en tu idioma.

Key java.orm.eager-fetch-type-on-association · Severity warning · Category orm

Declaring an association fetch = EAGER at the mapping level fetches it needlessly on every query of the owning entity. Leave it LAZY by default and eager-load per query when needed.

@Entity
public class Order {
@OneToMany(fetch = FetchType.EAGER) // items fetched on every Order query
private List<LineItem> items;
}
@Entity
public class Order {
@OneToMany(fetch = FetchType.LAZY)
private List<LineItem> items;
}
// when needed: SELECT o FROM Order o JOIN FETCH o.items

Declare associations LAZY and selectively eager-load with JOIN FETCH in the queries that need them.