我正在使用 Spring Data 并遇到问题HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
警告消息。
导致该问题的实体关系非常简单,我使用@NamedEntityGraph
它来获取所有数据:
@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;
}
我的存储库看起来像:
public interface CustomerRepository extends CrudRepository<Customer, Long> {
@EntityGraph(value = "customer-graph")
Page<Customer> findAll(Pageable pageable);
}
使用 sayfindAll(PageRequest.of(1, 1))
给我警告信息:
ohhinternal.ast.QueryTranslatorImpl : HHH000104: firstResult/maxResults 用集合获取指定;在内存中应用!
这对我来说很清楚,我明白为什么会这样。
我从@Vlad Mihalcea 那里看到了如何在使用 Hibernate 时修复它的很好的解释: https ://stackoverflow.com/a/46195656/5108737
但是有没有办法不使用 Hibernate 而仅使用 Spring Data 来修复它?