H2 db:如何解决功能" TOP"未找到; SQL语句

时间:2017-10-16 17:22:14

标签: java jpa spring-boot

您好我使用spring Specification编写查询,它看起来像这样。

select
        distinct TOP(?) project0_.idproject as idprojec1_40_,
        project0_.status as status2_40_ 
    from
        project project0_ 
    inner join
        project_info projectinf1_ 
            on project0_.idproject=projectinf1_.idproject 
    where
        lower(projectinf1_.proj_name) like ?

使用真实数据库工作正常但是当我使用h2本地数据库时,我在控制台中遇到了这个错误:

2017-10-16 18:58:56.808  WARN 14500 --- [io-8090-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 90022, SQLState: 90022
2017-10-16 18:58:56.808 ERROR 14500 --- [io-8090-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper   : Function "TOP" not found; SQL statement:

application.yml

spring:

  datasource:    
    driverClassName: org.h2.Driver
    url: jdbc:h2:file:~/project-data/dev;MODE=MSSQLServer
    username: sa
    password:
    initialize: True

  jpa:
    properties:
      hibernate:        
        ddl-auto: create 
        dialect: org.hibernate.dialect.SQLServer2008Dialect

        hbm2ddl:
          auto: create  
          import_files: enums.sql, import.sql

有任何建议如何解决? 修改
用法

Page<Project> page = projectRepository.findAll(getSpecifications(params), 
getPaging(params));

static Pageable getPaging(SearchParams params) {
    Integer pageNumber = params.getPageNumber() != null ? params.getPageNumber() : 0;
    Integer pageSize = params.getPageSize() != null ? params.getPageSize() : 15;
    return new PageRequest(pageNumber, pageSize);
}

static Specifications<Project> getSpecifications(SearchParams params) {
    return Specifications.where(new SearchSpecifications(params));
}

public class SearchSpecifications implements Specification<Project> {
    // some methods
    @Override
    public Predicate toPredicate(Root<Project> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
    // conditions
    }
}

0 个答案:

没有答案