【问题标题】:Spring Pageable implementation on SQL Server 2008 - Offset clauseSQL Server 2008 上的 Spring Pageable 实现 - 偏移子句
【发布时间】:2018-12-07 20:23:07
【问题描述】:

我正在尝试使用 @Query 注释实现分页和排序存储库。查询很简单:

SELECT DISTINCT(B.batch), B.scanDate, COUNT(B.batchReferenceNumber) as TransactionCount FROM Batch B

我的数据库是 SQL Server。正在生成的查询是:

    select
    distinct batch0_.BatchNumber as col_0_0_,
    count(batch0_.BatchNumber) as col_8_0_ 
from
    BATCH batch0_ 
order by
    batch0_.BatchNumber asc offset ? rows fetch next ? rows only

我收到一个错误:'offset' 附近的语法不正确。

原因是直到 SQL Server 2012 才引入“偏移”。

有没有办法解决这个问题?还是我需要实现自己的存储库而不是使用接口?

【问题讨论】:

    标签: sql-server jpa spring-data-jpa


    【解决方案1】:

    offset/limit 子句的 SQL 由您的 JPA 提供程序生成。 您可以通过配置正确的 SqlDialect 来解决此问题,或者如果没有此类方言可用,您可能会对该项目提出问题。

    【讨论】:

    • 那是完美的。我将方言更改为 2008 年,现在可以使用。我什至能够摆脱 @Query 注释并直接使用 JPQL。
    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 2015-10-08
    • 2014-03-30
    • 1970-01-01
    • 2013-12-06
    • 2011-07-20
    • 1970-01-01
    相关资源
    最近更新 更多