即使我指定了计数查询,也不能使用具有动态排序和/或分页的本机查询 [英] Cannot use native queries with dynamic sorting and/or pagination even if I have specified the count query
问题描述
value =select * from paper_entry where owner is null or owner =?1,
countQuery =select count(*)from paper_entry where owner is not null或$ owner =?1,
nativeQuery = true)
$ b 页面findAll(Long userId,Pageable pageable);
我使用mysql 5.7,spring-data-jpa 1.11.3.RELEASE。正如你所看到的,我遵循 https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query 。但是我得到了这个错误。
引起:org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException:不能在动态排序和/或分页中使用原生查询方法public abstract org.springframework.data.domain.Page com.gbdata.entry.persistence.dao.PaperEntryRepository.findAll(java.lang.Long,org.springframework.data.domain.Pageable)
at org.springframework .data.jpa.repository.query.NativeJpaQuery。(NativeJpaQuery.java:55)〜[spring-data-jpa-1.11.3.RELEASE.jar:na]
at org.springframework.data.jpa.repository .query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:72)〜[spring-data-jpa-1.11.3.RELEASE.jar:na]
at ........
解决没? SQL里面加 ORDER BY?#{#pageable}
就可以了
@Query(
value =select * from paper_entry where owner is null or owner =?1 ORDER BY?#{#pageable},
countQuery =select count(*)from paper_entry where owner不是null或owner =?1 ORDER BY?#{#pageable},
nativeQuery = true)
页面findAll(Long userId,Pageable pageable);
这是问题。
@Query( value = "select * from paper_entry where owner is null or owner = ?1", countQuery = "select count(*) from paper_entry where owner is not null or owner = ?1", nativeQuery = true)
Page findAll(Long userId, Pageable pageable);
I use mysql 5.7, spring-data-jpa 1.11.3.RELEASE. As you can see, I follow the document https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query. However I got this error.
Caused by: org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException: Cannot use native queries with dynamic sorting and/or pagination in method public abstract org.springframework.data.domain.Page com.gbdata.entry.persistence.dao.PaperEntryRepository.findAll(java.lang.Long,org.springframework.data.domain.Pageable) at org.springframework.data.jpa.repository.query.NativeJpaQuery.(NativeJpaQuery.java:55) ~[spring-data-jpa-1.11.3.RELEASE.jar:na] at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:72) ~[spring-data-jpa-1.11.3.RELEASE.jar:na] at ........
解决没? SQL里面加 ORDER BY ?#{#pageable}
就可以了
@Query(
value = "select * from paper_entry where owner is null or owner = ?1 ORDER BY ?#{#pageable}",
countQuery = "select count(*) from paper_entry where owner is not null or owner = ?1 ORDER BY ?#{#pageable}",
nativeQuery = true)
Page findAll(Long userId, Pageable pageable);
It's duplicate of this question.
这篇关于即使我指定了计数查询,也不能使用具有动态排序和/或分页的本机查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!