Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2.0 pagination with oracle is not working

I currently migrate from Spring Boot 1.4 -> 2.0, then I have a problem:

@GetMapping("/sample")
public Page<SampleDTO> doSomethings(@RequestParam("name") String name, Pageable pageable)

My Repository:

public interface SampleRepository extends JpaRepository<Sample, String>, QuerydslPredicateExecutor<Sample> {
        Page<Sample> findByNameContainingIgnoreCase(String name, Pageable pageable);

So, when I call an API:

http://localhost:8088/api/v1/sample?name=abc&page=0&size=10&sort=name,asc

I noticed JPA has translated to this query:

Spring Boot 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 Boot 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

Which is not correct for Oracle query. Is it a bug ?

like image 976
Toan Dao Avatar asked Aug 14 '18 07:08

Toan Dao


1 Answers

So in Spring Boot 1.5, using only without specify any dialect everything is working fine:

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

But when I migrated to Spring Boot 2.0, dialect has to be defined with:

spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

Otherwise you will see the message:

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.

Thanks to @Simon Martinelli's comment. It really help me to spot my mistake :)

like image 64
Toan Dao Avatar answered Sep 19 '22 03:09

Toan Dao