spring.data.jpa.query :Cannot use native queries with dynamic sorting and/or pagination in method
2017-10-25 15:16
1296 查看
最近公司使用的是Spring.data.jpa.Query,第一次接触,很多不知道怎么用。
如果使用的是hql语句查询的话,里面的要查询的字段和where里面的字段都应该是对应的实体类里的属性,
如果使用sql查询数据表的话,里面要查询的字段和where条件里的字段都应该是数据表里的字段,sql语句记得加上 :nativeQuery = true.
例如:@Query(value = "select count(`id`) from cdkey_info ", nativeQuery = true)
但是注意,jqa的query使用原生sql查询的时候不支持排序的,需要在sql里面加上:ORDER BY ?#{#pageable}
如果使用的是hql语句查询的话,里面的要查询的字段和where里面的字段都应该是对应的实体类里的属性,
如果使用sql查询数据表的话,里面要查询的字段和where条件里的字段都应该是数据表里的字段,sql语句记得加上 :nativeQuery = true.
例如:@Query(value = "select count(`id`) from cdkey_info ", nativeQuery = true)
但是注意,jqa的query使用原生sql查询的时候不支持排序的,需要在sql里面加上:ORDER BY ?#{#pageable}
相关文章推荐
- SpringData JPA @Query分页查询 Cannot use native queries with dynamic sorting and/or pagination in method
- Spring Data JPA(2)--利用PagingAndSortingRespository实现分页和排序
- 异常:The absolute uri: http://www.springframework.org/security/tags cannot be resolved in either web.xml or the jar files deployed with this application
- 结合SpringDataJPA中的PagingAndSortingRepository和 JpaSpecificationExecutor接口实现大数据量的数据分页查询
- SpEL support in Spring Data JPA @Query definitions
- Distributed transactions with multiple databases, Spring Boot, Spring Data JPA and Atomikos
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-002设置JPA的EntityManagerFactory(<persistence-unit>、<jee:jndi-lookup>)
- The text, ntext, and image data types are invalid in this subquery or aggregate expression.
- @Query Annotation in Spring Data JPA--转
- 【SpringData】轻松愉快之玩转SpringData( 第5章 CrudRepository PagingAndSortingRespsitory JpaRepository接口)
- How to setup multiple data sources with Spring and JPA
- 深入浅出学Spring Data JPA toPredicate Predicate[] p = new Predicate[list.size()]; query.where(cb.and 201
- Spring boot data JPA 自定义JPQL语句,以及PagingAndSortingRepository接口实现分页查询
- IntelliJ IDEA can't resolve entity in spring data jpa @query annotation 报红
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-003编写JPA-based repository( @PersistenceUnit、 @PersistenceContext、PersistenceAnnotationBeanPostProcessor)
- Along with all the above benefits, you cannot overlook the space efficiency and performance gains in using DataFrames and Dataset APIs for two reasons.
- Spring Data jpa @query 关于IN关键字查询
- How to setup multiple data sources with Spring and JPA
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则(@EnableJpaRepositories、<jpa:repositories>)
- Distributed transactions with multiple databases, Spring Boot, Spring Data JPA and Atomikos