springboot2.0+jpa+oracle 分页 ORA-00933: SQL 命令未正确结束

最近做了一个demo例子,数据库使用的是oracle 12c,用到的框架和技术如下POM:



  4.0.0

  com.example
  demo
  0.0.1-SNAPSHOT
  jar

  demo
  Demo project for Spring Boot

  
    org.springframework.boot
    spring-boot-starter-parent
    2.0.1.RELEASE
     
  

  
    springboot
    UTF-8
    UTF-8
    1.8
  

  
    
      org.springframework.boot
      spring-boot-starter
    
    
      org.springframework.boot
      spring-boot-starter-thymeleaf
    
    
      org.springframework.boot
      spring-boot-devtools
      true
      true
    
    
      org.springframework.boot
      spring-boot-starter-web
    
    
      mysql
      mysql-connector-java
    
    
      org.springframework.boot
      spring-boot-starter-data-redis
    
    
      org.springframework.session
      spring-session-data-redis
    
    
      org.mybatis.spring.boot
      mybatis-spring-boot-starter
      1.3.2
    
    
      org.springframework.boot
      spring-boot-starter-data-jpa
    
    
      org.springframework.boot
      spring-boot-starter-test
      test
    
    
      com.oracle
      ojdbc6
      11.2.0.3
    
    
      org.quartz-scheduler
      quartz
      2.3.0
    
    
      org.quartz-scheduler
      quartz-jobs
      2.3.0
    
    
      org.apache.commons
      commons-lang3
      3.7
    
    
    
    
    
    
  

  
    
      
        org.springframework.boot
        spring-boot-maven-plugin
        
          true
        
      
      
      
        com.spotify
        docker-maven-plugin
        1.0.0
        
          ${docker.image.prefix}/${project.artifactId}
          src/main/docker
          
            
              /
              ${project.build.directory}
              ${project.build.finalName}.jar
            
          
        
      
      
    
  

在使用jpa做分页查询的时候报了一个错误

java.sql.SQLSyntaxErrorException: ORA-00933: SQL 命令未正确结束

查看打印的sql:select X from X where X limit ? 

oracle不支持limit的用法,需要在application.properties增加以下配置

#hibernate数据库方言配置:

#org.hibernate.dialect.Oracle9iDialect,org.hibernate.dialect.Oracle10gDialect,org.hibernate.dialect.Oracle12cDialect;

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect

增加配置后,输出的sql为:select X from X where X fetch first ? rows only;

-----------------------------------------------------------------------

从springboot 1.X到springboot 2.X要注意的有

1.findOne(Long id) 改成 findById(Long id).get();

2.构造分页时参数时 new PageRequest(0, 10, sort) 改成 findAll(specification, PageRequest.of(0, 1, sort));

你可能感兴趣的:(springboot2.0+jpa+oracle 分页 ORA-00933: SQL 命令未正确结束)