gpt4 book ai didi

java - 使用 Oracle 的 Spring Boot 2.0 分页不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:20:09 24 4
gpt4 key购买 nike

我目前从 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 的评论。它真的帮助我发现了我的错误:)

关于java - 使用 Oracle 的 Spring Boot 2.0 分页不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51835595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com