spring jpa休眠mariadb

ryoqjall  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(417)

我正在尝试从spring-jpa-hibernate应用程序连接到mariadb v10.2.14。我正在使用

driverClassName: com.mysql.jdbc.Driver

以及

setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");

我有一个查询方法,通过使用“findtop1”关键字来查找最上面的第一行。。。当查询实际形成时,它使用“偏移0行仅获取下1行”而不是“限制0,1…”。。。因此,maria db服务器抛出一个错误。。。
如何使用limit子句而不是offset fetch更改驱动程序/方言文件以形成查询。。
注意:我尝试了mariadbdialect和mariadb driverclass名称的所有组合,比如org.hibernate.dialect.mariadb53dialect和org.mariadb.jdbc.driver。。
下面是我得到的例外

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
hkmswyz6

hkmswyz61#

预打印查询:

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 .)

相关问题