首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >spring JPA Hibernate MariaDB

spring JPA Hibernate MariaDB
EN

Stack Overflow用户
提问于 2018-06-28 02:16:32
回答 1查看 1.2K关注 0票数 0

我正在尝试从我的spring JPA hibernate应用程序连接到mariaDB v10.2.14。我正在使用

代码语言:javascript
复制
driverClassName: com.mysql.jdbc.Driver

代码语言:javascript
复制
setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");

我有一个查询方法,通过使用"findTop1“关键字来查找顶部第一行...当查询实际形成时,它使用“偏移量0行仅获取下一行1行”而不是限制0,1 ...因此,maria DB服务器抛出一个错误...

如何更改驱动程序/方言文件以使用LIMIT子句而不是offset-fetch形成查询。

注意:我已经尝试了mariadb方言和mariadb驱动程序类名的所有组合,如org.hibernate.dialect.MariaDB53Dialect和org.mariadb.jdbc.Driver。

下面是我得到的异常

代码语言:javascript
复制
2018-06-27 11:31:19.936  INFO 10484 --- [nio-8080-exec-2] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select aboutpage0_.id as id1_0_, aboutpage0_.APPLICATION_NAME as APPLICAT2_0_, aboutpage0_.createdDate as createdD3_0_, aboutpage0_.effectiveDate as effectiv4_0_, aboutpage0_.LAST_UPD_TS as LAST_UPD5_0_, aboutpage0_.LAST_UPD_SYSUSR_ID as LAST_UPD6_0_, aboutpage0_.version as version7_0_ from XXXXX aboutpage0_ where aboutpage0_.APPLICATION_NAME=? and aboutpage0_.effectiveDate<=? order by aboutpage0_.LAST_UPD_TS desc, aboutpage0_.effectiveDate desc offset 0 rows fetch next ? rows only
2018-06-27 11:31:20.112  WARN 10484 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1064, SQLState: 42000
2018-06-27 11:31:20.112 ERROR 10484 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper   : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'offset 0 rows fetch next 1 rows only' at line 1
2018-06-27 11:31:20.142 ERROR 10484 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'offset 0 rows fetch next 1 rows only' at line 1
EN

回答 1

Stack Overflow用户

发布于 2018-06-28 12:41:55

预打印查询:

代码语言:javascript
复制
select  aboutpage0_.id as id1_0_, aboutpage0_.APPLICATION_NAME as APPLICAT2_0_,
        aboutpage0_.createdDate as createdD3_0_, aboutpage0_.effectiveDate as effectiv4_0_,
        aboutpage0_.LAST_UPD_TS as LAST_UPD5_0_, aboutpage0_.LAST_UPD_SYSUSR_ID as LAST_UPD6_0_,
        aboutpage0_.version as version7_0_
    from  XXXXX aboutpage0_
    where  aboutpage0_.APPLICATION_NAME=?
      and  aboutpage0_.effectiveDate<=?
    order by  aboutpage0_.LAST_UPD_TS desc,
              aboutpage0_.effectiveDate desc
    offset 0 rows fetch next ? rows only 2018-06-27 

这应该说明在从Hibernate创建SQL时出现了错误。它可能会指向limit 1 offset 0,但失败了。(注意:LIMIT先于OFFSET。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51069104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档