Liquibase原因“无法准备陈述; sql;只有H2
我将Liquibase集成到春季启动应用程序中。与MariadB一起使用它可以正常工作。
对于单位&集成测试我使用H2内存数据库。在运行测试时会导致以下例外:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select user0_.id as id1_19_0_, user0_.created_at as created_2_19_0_, user0_.updated_at as updated_3_19_0_, user0_.version as version4_19_0_, user0_.activated as activate5_19_0_, user0_.birthday as birthday6_19_0_, user0_.email as email7_19_0_, user0_.firstname as firstnam8_19_0_, user0_.force_password_change as force_pa9_19_0_, user0_.password_hash as passwor10_19_0_, user0_.role as role11_19_0_, user0_.surname as surname12_19_0_ from users user0_ where user0_.id=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:259) ~[spring-orm-5.3.19.jar:5.3.19]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:233) ~[spring-orm-5.3.19.jar:5.3.19]
我的prod config(工作):
spring:
main:
allow-bean-definition-overriding: true
datasource:
url: jdbc:mariadb://localhost:3307/testdb
username: user
password: psw
jpa:
generate-ddl: false
database-platform: org.hibernate.dialect.MariaDB103Dialect
sql:
init:
mode: never
liquibase:
enabled: true
change-log: classpath:db/db.changelog-master.yaml
我的测试配置(不起作用):
spring:
main:
allow-bean-definition-overriding: true
datasource:
url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;NON_KEYWORDS=user
username: sa
driver-class-name: org.h2.Driver
password: password
jpa:
database-platform: org.hibernate.dialect.H2Dialect
generate-ddl: false
sql:
init:
mode: never
liquibase:
change-log: classpath:db/db.changelog-master.yaml
enabled: true
test:
database:
replace: none
我尝试的:
- 包括
non_keywords
来自H2的多个URL配置,以排除用户的问题也许被解释为关键字。
由于它正在与Mariadb合作,因此我认为这是与H2相关的问题。
感谢任何帮助,文档,链接任何内容:)
I integrated Liquibase in my Spring Boot application. Using it with MariaDB works fine.
For unit & integration testing I use a H2 in-memory database. While running tests it causes following exception:
org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select user0_.id as id1_19_0_, user0_.created_at as created_2_19_0_, user0_.updated_at as updated_3_19_0_, user0_.version as version4_19_0_, user0_.activated as activate5_19_0_, user0_.birthday as birthday6_19_0_, user0_.email as email7_19_0_, user0_.firstname as firstnam8_19_0_, user0_.force_password_change as force_pa9_19_0_, user0_.password_hash as passwor10_19_0_, user0_.role as role11_19_0_, user0_.surname as surname12_19_0_ from users user0_ where user0_.id=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:259) ~[spring-orm-5.3.19.jar:5.3.19]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:233) ~[spring-orm-5.3.19.jar:5.3.19]
My prod config (working):
spring:
main:
allow-bean-definition-overriding: true
datasource:
url: jdbc:mariadb://localhost:3307/testdb
username: user
password: psw
jpa:
generate-ddl: false
database-platform: org.hibernate.dialect.MariaDB103Dialect
sql:
init:
mode: never
liquibase:
enabled: true
change-log: classpath:db/db.changelog-master.yaml
My test config (not working):
spring:
main:
allow-bean-definition-overriding: true
datasource:
url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;NON_KEYWORDS=user
username: sa
driver-class-name: org.h2.Driver
password: password
jpa:
database-platform: org.hibernate.dialect.H2Dialect
generate-ddl: false
sql:
init:
mode: never
liquibase:
change-log: classpath:db/db.changelog-master.yaml
enabled: true
test:
database:
replace: none
What I tried:
- Multiple url configs including the
NON_KEYWORDS
option from H2 to exclude problems with user as it is maybe interpreted as a keyword.
As it is working with MariaDB I think it is a problem related to H2.
Thankful for any help, documentation, link whatever :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,问题在于我的模式。由于H2不支持Mariadb的某些功能,因此它没有启动,因此JPA无法准备SQL语句,因为表不存在。
Actually, the problem was with my schema. As H2 does not support some features MariaDB does, it is not starting and therefore jpa is not able to prepare the SQL statement as the tables do not exist.