【问题标题】:SpringData extending JpaSpecificationExecutor errorSpring Data 扩展 JpaSpecificationExecutor 错误
【发布时间】:2012-07-15 07:08:18
【问题描述】:

我有一个很奇怪的问题。在我的存储库中,我需要扩展JpaSpecificationExecutor<T> 接口以便能够使用findAll(Specification<T>, Pageable) 进行自定义查询分页。

但是,当我使用 JpaSpecificationExecutor 时,

public interface DescriptionRepository extends ParentRepositoryCustom<Description, Long>,
        JpaSpecificationExecutor<Description> {

} 

应用程序无法构建,抛出 No property count found for type class Description 异常。

我的Description 类没有计数属性。当我从存储库中删除 JpaSpecificationExecutor 时,一切都恢复正常了。

【问题讨论】:

    标签: java spring-data spring-data-jpa


    【解决方案1】:

    我遇到了同样的异常。就我而言,原因是 ParentRepositoryImpl 没有正确扩展 SimpleJpaRepository 这是 JpaSpecificationExecutor 的一个实现。 因此,当 Spring 尝试解析查询名称时,它会排除属于 Spring 调用的实现的 repositoryBaseClass 的方法名称。它在 org.springframework.data.repository.core.support.DefaultRepositoryInformation 类中

    public boolean isBaseClassMethod(Method method) {
        return isTargetClassMethod(method, repositoryBaseClass);
    }
    

    检查 repositoryBaseClass 是否符合您的预期。它应该定义“count”方法。

    如果您没有扩展正确的超类,则方法(在您的情况下为“count”)不排除在解析中,Spring 尝试通过根据其名称结构创建查询来构建查询......在这种情况下名称片段将针对您的实体属性进行测试。

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-06
      • 1970-01-01
      • 2018-09-18
      • 1970-01-01
      • 2017-06-21
      • 1970-01-01
      相关资源
      最近更新 更多