您的位置:首页 > 编程语言 > Java开发

SpringData JPA @Query分页查询 Cannot use native queries with dynamic sorting and/or pagination in method

2017-07-21 09:47 741 查看
异常信息:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'newsDao': Invocation of init method failed; nested exception is 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.example.demo.repository.NewsDao.findByTitle(java.lang.String,org.springframework.data.domain.Pageable)


执行sql

//分页 nativeQuery=true 表示采用原生SQL语句进行操作
@Query(value = "select id,title,content from news where title =?1",
countQuery = "select count(*) from news where title =?1",
nativeQuery = true)
Page<News> findByTitle(String title, Pageable pageable);


修改成:

//分页 nativeQuery=true 表示采用原生SQL语句进行操作
@Query(value = "select id,title,content from News n where n.title =?1",
countQuery = "select count(*) from News n where n.title =?1",
nativeQuery = false)
Page<News> findByTitle(String title, Pageable pageable);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  分页 jpa
相关文章推荐