I'm using Spring Data and faced up the issue HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
warning message.
The entity relationship that cause that issue is pretty simple, I use @NamedEntityGraph
in order to fetch all data:
@NamedEntityGraph(
name = "customer-graph",
attributeNodes = @NamedAttributeNode(
value = "order",
subgraph = "sub-graph"
),
subgraphs = @NamedSubgraph(
name = "sub-graph",
attributeNodes = @NamedAttributeNode("products")
)
)
@Entity
public class Customer {
@Id
private Long id;
@OneToOne(fetch = FetchType.LAZY)
private Order order;
}
@Entity
public class Order {
@Id
private Long orderId;
@ManyToMany(fetch = FetchType.LAZY)
private Set<Product> products = new HashSet<>();
}
@Entity
public class Product {
@Id
private Long id;
private String name;
}
And my repository looks like:
public interface CustomerRepository extends CrudRepository<Customer, Long> {
@EntityGraph(value = "customer-graph")
Page<Customer> findAll(Pageable pageable);
}
Using say findAll(PageRequest.of(1, 1))
gives me warning message:
o.h.h.internal.ast.QueryTranslatorImpl : HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
It's pretty clear for me and I understand why it's happened.
I've seen quite good explanation from @Vlad Mihalcea how to fix it when using Hibernate: https://stackoverflow.com/a/46195656/5108737
But is there a way to fix it using not Hibernate, but Spring Data only?