当前位置: 首页 > 工具软件 > Insql > 使用案例 >

解决数据库H2 error: “Syntax error in SQL statement ... expected identifier“

商飞航
2023-12-01

Syntax error in SQL statement "select user0_.user_id as col_0_0_ from [*]user user0_ where user0_.email=? limit ?"; expected "identifier"; SQL statement:
select user0_.user_id as col_0_0_ from user user0_ where user0_.email=? limit ? [42001-212]

问题产生的原因是Hibernate/JPA生成的表与数据库保留字冲突,如‘USER’表, 解决的方法是修改表名,或者数据库取消冲突的保留字:

在配置表中设置:NON_KEYWORDS=USER

其中完整的设置例如下:

spring.datasource.url=jdbc:h2:mem:testdb;NON_KEYWORDS=USER
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=

spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

参考网址:

https://blog.dkwr.de/development/fix-h2-error-expected-identifeir/

 类似资料: