简体   繁体   English

H2版本升级后org.h2.jdbc.JdbcSQLSyntaxErrorException

[英]org.h2.jdbc.JdbcSQLSyntaxErrorException after H2 version upgrade

I recently upgraded h2 version from 1.4.200 to 2.0.206.我最近将 h2 版本从 1.4.200 升级到 2.0.206。 Some of the queries that used to work in the older version are not working properly after the upgrade.一些以前在旧版本中工作的查询在升级后无法正常工作。

CREATE TABLE SOMETABLE (
  ID INT(11) NOT NULL AUTO_INCREMENT,
  SOURCE_ID VARCHAR(255) NOT NULL,
  MESSAGE VARCHAR(255) NOT NULL,
  PRIMARY KEY (`ID`)
);
CREATE TABLE IF NOT EXISTS SOMEOTHERTABLE (
    ID VARCHAR(255) NOT NULL,
    NAME VARCHAR(255) NOT NULL,
    CREATED_TIME TIMESTAMP NOT NULL,
    LAST_MODIFIED TIMESTAMP NOT NULL,
    HAS_FILE BOOLEAN(1) NOT NULL,
    PRIMARY KEY (ID)
);

For both these, I get similar errors对于这两个,我得到类似的错误

org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "  CREATE TABLE SOMETABLE ( ID INT([*]11) NOT NULL AUTO_INCREMENT, SOURCE_ID VARCHAR(255) NOT NULL, MESSAGE VARCHAR(255) NOT NULL, PRIMARY KEY (`ID`) )"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, AUTO_INCREMENT, ., )";
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "  CREATE TABLE IF NOT EXISTS SOMEOTHERTABLE ( ID VARCHAR(255) NOT NULL, NAME VARCHAR(255) NOT NULL, CREATED_TIME TIMESTAMP NOT NULL, LAST_MODIFIED TIMESTAMP NOT NULL, HAS_FILE BOOLEAN([*]1) NOT NULL, PRIMARY KEY (ID) )"; expected "ARRAY, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, DEFAULT, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, COMMENT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, AUTO_INCREMENT, ., )";

It seems that in both these cases, having INT(11) and BOOLEAN(1) is the issue.似乎在这两种情况下,都有INT(11)BOOLEAN(1)是问题所在。 Are those not allowed anymore in the new version?这些在新版本中不再允许了吗? If so, how should I change those?如果是这样,我应该如何改变这些? Any help regarding this is appreciated.对此的任何帮助表示赞赏。

Why do you have such definitions?你为什么有这样的定义? Documentation of H2 1.4.200 doesn't allow any parameters for these data types. H2 1.4.200 的文档不允许这些数据类型的任何参数。

INT(11) is allowed only in MySQL and MariaDB compatibility modes, but the specified precision is ignored by H2. INT(11)仅在 MySQL 和 MariaDB 兼容模式下允许,但指定的精度被 H2 忽略。 This definition is rejected in all other compatibility modes in H2 2.0, you need to use INT or INTEGER .此定义在 H2 2.0 中的所有其他兼容模式下均被拒绝,您需要使用INTINTEGER

BOOLEAN(1) is not allowed at all, if it worked in 1.4.200, it was a bug in the parser.根本不允许使用BOOLEAN(1) ,如果它在 1.4.200 中工作,那是解析器中的一个错误。 You need to use BOOLEAN .您需要使用BOOLEAN

AUTO_INCREMENT clause also should normally be used only in MySQL and MariaDB compatibility modes, but it works in Regular mode too. AUTO_INCREMENT子句通常也只能在 MySQL 和 MariaDB 兼容模式下使用,但它也适用于常规模式。 The proper clause is GENERATED BY DEFAULT AS IDENTITY and explicit NOT NULL constraint isn't required for primary key and identity columns, you can remove it.正确的子句GENERATED BY DEFAULT AS IDENTITY ,并且主键和标识列不需要显式NOT NULL约束,您可以将其删除。 Constraints also should normally be specified after all other clauses, NOT NULL before identity options is actually accepted by H2, but this wrong order of clauses isn't documented and isn't supported.通常还应该在所有其他子句之后指定约束,而NOT NULL ,但是这种错误的子句顺序没有记录并且不受支持。

I was facing the same issue when updating the h2 version from 1.4.200 to 2.0.206.将 h2 版本从 1.4.200 更新到 2.0.206 时,我遇到了同样的问题。 The project is based on Spring Boot and uses Hibernate.该项目基于Spring Boot,使用Hibernate。

In my case the problem was, that i had an entity with a field referencing a table column called "VALUE".就我而言,问题是,我有一个实体,其字段引用名为“VALUE”的表列。

@Column(name = "VALUE")
private BigDecimal value;

According to the docs https://h2database.com/html/advanced.html#keywords , VALUE is a reserved keyword.根据文档https://h2database.com/html/advanced.html#keywords , VALUE 是保留关键字。 Changing the column reference "VALUE" to something like "VALUE1" solved the issue.将列引用“VALUE”更改为“VALUE1”之类的内容解决了这个问题。

Had a similar issue with Hibernate and Spring Boot and as @Plumstone mentioned it was due to a reserved keyword (in my case constraint ).与 Hibernate 和 Spring Boot 有类似的问题,正如@Plumstone所说,这是由于保留关键字(在我的情况下为constraint )。 Adding backticks to the name, solved the issue:在名称中添加反引号,解决了这个问题:

@Column(name = "`constraint`")
private String constraint;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 插入时间戳记时,H2 org.h2.jdbc.JdbcSQLSyntaxErrorException - H2 org.h2.jdbc.JdbcSQLSyntaxErrorException when inserting a Timestamp org.h2.jdbc.JdbcSQLSyntaxErrorException h2 数据库 java - org.h2.jdbc.JdbcSQLSyntaxErrorException h2 database java Spring JPA H2 数据库获取 org.h2.jdbc.JdbcSQLSyntaxErrorException 未找到表 - Spring JPA H2 database get org.h2.jdbc.JdbcSQLSyntaxErrorException Table not found org.h2.jdbc.JdbcSQLSyntaxErrorException:找不到列; SQL 声明 [SPRINGBOOT] - org.h2.jdbc.JdbcSQLSyntaxErrorException: Column not found; SQL statement [SPRINGBOOT] org.h2.jdbc.JdbcSQLSyntaxErrorException:SQL 语句中的语法错误 - org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement 引起:org.h2.jdbc.JdbcSQLSyntaxErrorException:Function “SYSUTCDATETIME”未找到; SQL 声明:[90022-200] - Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Function "SYSUTCDATETIME" not found; SQL statement:[90022-200] Spring SQL:org.h2.jdbc.JdbcSQLSyntaxErrorException:SQL 语句中的语法错误“;预期为“标识符”,使用 INSERT INTO 时 - Spring SQL: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "; expected "identifier", when using INSERT INTO org.h2.jdbc.JdbcSQLSyntaxErrorException:找不到列“USER0_.PROFILE_ID”; SQL 声明: - org.h2.jdbc.JdbcSQLSyntaxErrorException : Column "USER0_.PROFILE_ID" not found; SQL statement: 如何修复 org.h2.jdbc.JdbcSQLSyntaxErrorException:SQL 语句中的语法错误需要“标识符” - How to fix org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement expected "identifier" 带有 h2 和 jooq 的 JdbcSQLSyntaxErrorException - JdbcSQLSyntaxErrorException with h2 and jooq
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM