Я пытаюсь подключиться к mariaDB v10.2.14 из моего приложения JPH hibernate. я использую
driverClassName: com.mysql.jdbc.Driver
а также
setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
У меня есть метод запроса, чтобы найти верхнюю первую строку, используя ключевые слова "findTop1"... когда запрос действительно сформирован, он использует "смещение 0 строк, выбирающих только следующие 1 строки" вместо LIMIT 0,1... потому что этого сервера maria DB выдает ошибку...
как я могу изменить файл драйвера/диалекта, чтобы сформировать запрос, используя предложение LIMIT вместо offset-fetch.
note: я пробовал все комбинации имен 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
Подтверждение запроса:
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
должно сделать очевидным, что что-то пошло не так в создании SQL из Hibernate. Вероятно, он возглавил высказывание limit 1 offset 0
, но потерпел неудачу. (Примечание: LIMIT
перед OFFSET
.)