Spring 使用 Oracle 的 Boot 2.0 分页不工作
Spring Boot 2.0 pagination with oracle is not working
我目前从 Spring Boot 1.4 -> 2.0 迁移,然后我遇到了问题:
@GetMapping("/sample")
public Page<SampleDTO> doSomethings(@RequestParam("name") String name, Pageable pageable)
我的存储库:
public interface SampleRepository extends JpaRepository<Sample, String>, QuerydslPredicateExecutor<Sample> {
Page<Sample> findByNameContainingIgnoreCase(String name, Pageable pageable);
所以,当我调用 API:
http://localhost:8088/api/v1/sample?name=abc&page=0&size=10&sort=name,asc
我注意到 JPA 已转换为此查询:
Spring 引导 1.5
select *
from ( select row_.*, rownum rownum_
from ( select ... from sample sample0_ where upper(sample0_.name) like upper(?)
order by sample0_.name asc )
row_ where rownum <= ?) where rownum_ > ?
Spring 启动 2.0
select ...
from sample sample0_
where upper(sample0_.name) like upper(?)
order by sample0_.name asc fetch first ? rows only
-->>> 2018-08-14 14:45:04 ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-00933: SQL command not properly ended
这对于 Oracle 查询是不正确的。这是一个错误吗?
所以在 Spring Boot 1.5 中,仅使用而不指定任何方言一切正常:
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
但是当我迁移到 Spring Boot 2.0 时,方言必须定义为:
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
否则您将看到消息:
2018-08-14 17:11:02 WARN c.z.hikari.util.DriverDataSource - Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
感谢@Simon Martinelli 的评论。它真的帮助我发现了我的错误:)
我目前从 Spring Boot 1.4 -> 2.0 迁移,然后我遇到了问题:
@GetMapping("/sample")
public Page<SampleDTO> doSomethings(@RequestParam("name") String name, Pageable pageable)
我的存储库:
public interface SampleRepository extends JpaRepository<Sample, String>, QuerydslPredicateExecutor<Sample> {
Page<Sample> findByNameContainingIgnoreCase(String name, Pageable pageable);
所以,当我调用 API:
http://localhost:8088/api/v1/sample?name=abc&page=0&size=10&sort=name,asc
我注意到 JPA 已转换为此查询:
Spring 引导 1.5
select *
from ( select row_.*, rownum rownum_
from ( select ... from sample sample0_ where upper(sample0_.name) like upper(?)
order by sample0_.name asc )
row_ where rownum <= ?) where rownum_ > ?
Spring 启动 2.0
select ...
from sample sample0_
where upper(sample0_.name) like upper(?)
order by sample0_.name asc fetch first ? rows only
-->>> 2018-08-14 14:45:04 ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ORA-00933: SQL command not properly ended
这对于 Oracle 查询是不正确的。这是一个错误吗?
所以在 Spring Boot 1.5 中,仅使用而不指定任何方言一切正常:
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
但是当我迁移到 Spring Boot 2.0 时,方言必须定义为:
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
否则您将看到消息:
2018-08-14 17:11:02 WARN c.z.hikari.util.DriverDataSource - Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.
感谢@Simon Martinelli 的评论。它真的帮助我发现了我的错误:)