intentionality - efficient
FetchType
is an enumeration in the Java Persistence API (JPA) that is used to define the fetching strategy for associations
(relationships) between entities in a relational database.
There are two main values for FetchType:
-
FetchType.EAGER
: the association is loaded immediately when the owning entity is loaded.
-
FetchType.LAZY
: the association is not loaded unless it is explicitly accessed.
This rule raises an issue when the fetch
argument is explicitly set to FetchType.EAGER
.
Why is this an issue?
How can I fix it?
More Info
Using FetchType.EAGER
can lead to inefficient data loading and potential performance issues. Eager Loading initializes associated data
on the spot, potentially fetching more data than needed.