验证在继承接口中的公共抽象方法的查询失败。

huangapple 未分类评论43阅读模式
英文:

Validation failed for query for method public abstract in inherited interface

问题

我在继承此方法时遇到以下错误:

  1. Caused by: java.lang.IllegalArgumentException: 调用公共抽象方法 java.util.List com.vw.asa.repositories.base.BaseCmsRepository.getAllByDescFilter(java.lang.String,org.springframework.data.domain.Pageable) 时验证失败!
  2. at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:93)
  3. at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:63)
  4. at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:76)
  5. at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:56)
  6. at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:140)
  7. at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:207)
  8. at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:78)
  9. at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:574)
  10. at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:567)
  11. at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  12. at java.util.Iterator.forEachRemaining(Iterator.java:116)

这是引发错误的类,附带错误行注释:

  1. @NoRepositoryBean
  2. public interface BaseCmsRepository<T, ID extends Serializable> extends BaseRepository<T, ID> {
  3. @Query("SELECT a FROM #{#entityName} a WHERE a.parentId = :parent_id")
  4. List<T> getAllChildrenOf(
  5. @Param("parent_id") Integer parent_id
  6. );
  7. @Query("SELECT a FROM #{#entityName} a WHERE a.isActive = 1 AND a.name LIKE %:filter% ORDER by a.name ASC")
  8. List<T> getAllByNameFilter(
  9. @Param("filter") String filter,
  10. Pageable pageable
  11. );
  12. // ** 这是引发错误的行 **
  13. @Query("SELECT a FROM #{#entityName} a WHERE a.isActive = 1 AND a.desc LIKE %:filter% ORDER by a.name ASC")
  14. List<T> getAllByDescFilter(
  15. @Param("filter") String filter,
  16. Pageable pageable
  17. );
  18. }

不太清楚为什么这行会触发错误,而其他行则不会。也许我漏掉了一个显而易见的错误,只需要多一双眼睛看看吗?

英文:

I am getting the following error when inheriting this method:

  1. Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.vw.asa.repositories.base.BaseCmsRepository.getAllByDescFilter(java.lang.String,org.springframework.data.domain.Pageable)!
  2. at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:93)
  3. at org.springframework.data.jpa.repository.query.SimpleJpaQuery.&lt;init&gt;(SimpleJpaQuery.java:63)
  4. at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:76)
  5. at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:56)
  6. at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:140)
  7. at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:207)
  8. at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:78)
  9. at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:574)
  10. at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:567)
  11. at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
  12. at java.util.Iterator.forEachRemaining(Iterator.java:116)

This is the offending class with noted line of error:

<!-- language: java -->

  1. @NoRepositoryBean
  2. public interface BaseCmsRepository&lt;T, ID extends Serializable&gt; extends BaseRepository&lt;T, ID&gt; {
  3. @Query(&quot;SELECT a FROM #{#entityName} a WHERE a.parentId = :parent_id&quot;)
  4. List&lt;T&gt; getAllChildrenOf(
  5. @Param(&quot;parent_id&quot;) Integer parent_id
  6. );
  7. @Query(&quot;SELECT a FROM #{#entityName} a WHERE a.isActive = 1 AND a.name LIKE %:filter% ORDER by a.name ASC&quot;)
  8. List&lt;T&gt; getAllByNameFilter(
  9. @Param(&quot;filter&quot;) String filter,
  10. Pageable pageable
  11. );
  12. // ** THIS IS THE OFFENDING LINE **
  13. @Query(&quot;SELECT a FROM #{#entityName} a WHERE a.isActive = 1 AND a.desc LIKE %:filter% ORDER by a.name ASC&quot;)
  14. List&lt;T&gt; getAllByDescFilter(
  15. @Param(&quot;filter&quot;) String filter,
  16. Pageable pageable
  17. );
  18. }

Not sure why this line triggers it, but the others do not. Maybe I am missing a glaring mistake, and just need a second set of eyes?

huangapple
  • 本文由 发表于 2020年4月5日 02:37:05
  • 转载请务必保留本文链接:https://java.coder-hub.com/61032998.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定