使用QueryDslPredicateExecutor的Spring数据没有找到类型错误的属性findAll

时间:2016-10-08 19:25:11

标签: spring spring-boot spring-data spring-data-jpa querydsl

我尝试按照Spring Data JPA with QueryDSL

中的教程进行操作

我的代码版本如下:  spring-boot = 1.3.8.release  query-dsl = 3.7.4

我的实体如下

@Entity
@Table(name = BatchAPIEntity.TABLE)
public class BatchAPIEntity extends BatchEntity {

    @JsonView(View.API.class)
    @Column(name = KEY_NIT)
    String nit;
}

我的存储库是以下

public interface BatchApiRepository extends JpaRepository<BatchAPIEntity,Long>, QueryDslPredicateExecutor<BatchAPIEntity>{}

当我编译并构建代码时,显示以下错误

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type BatchAPIEntity!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329)
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272)
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243)
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76)
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:235)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:373)
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:353)
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:84)
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:62)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:100)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:211)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:74)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:416)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1641)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    ... 47 common frames omitted

我的错误与以下问题中给出的类似,但问题是它没有回答

Error in findAll

我也试过这个答案,但没有任何好结果

https://stackoverflow.com/a/37800554/5192019

1 个答案:

答案 0 :(得分:0)

我可以解决这个问题的方法是在使用QueryDslJpaRepository后使用QueryDslJpaRepository而不是两个独立的接口,如下所示:

public interface BatchApiRepository extends QueryDslJpaRepository<BatchAPIEntity, Long>