Spring boot 我们能让Spring JPA规范与EntityGraph一起工作吗?

Spring boot 我们能让Spring JPA规范与EntityGraph一起工作吗?,spring-boot,jpa,spring-data-jpa,entitygraph,Spring Boot,Jpa,Spring Data Jpa,Entitygraph,我正在实体上使用JPA规范实现一个动态查询逻辑。该实体与其他实体具有多个关系。我遇到了在执行JPA规范时生成太多查询的问题 有没有一种方法可以将JPA规范findAll(规范,页面)与EntityGraph结合起来,这样我们就可以在执行相同的查询时生成一个查询?是的,使用EntityGraphJKPASSpecificationExecutor传递EntityGraph是绝对可能的 @Repository public interface UserRepository exten

我正在实体上使用JPA规范实现一个动态查询逻辑。该实体与其他实体具有多个关系。我遇到了在执行JPA规范时生成太多查询的问题


有没有一种方法可以将JPA规范
findAll(规范,页面)
与EntityGraph结合起来,这样我们就可以在执行相同的查询时生成一个查询?

是的,使用
EntityGraphJKPASSpecificationExecutor
传递
EntityGraph
是绝对可能的

@Repository
public interface UserRepository
        extends JpaRepository<EntityClassName, DatatypeOfPrimaryKey>, EntityGraphJpaSpecificationExecutor<EntityClassName> {
}

userRepository.findAll(specification, pageable, new NamedEntityGraph(EntityGraphType.FETCH, "graphName"))
@存储库
公共接口用户存储库
扩展JpaRepository、EntityGraphJPASSpecificationExecutor{
}
findAll(规范,可分页,新名称dentityGraph(EntityGraphType.FETCH,“graphName”))