首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >升级到SpringBoot2.7时失败的测试-- "CommandAcceptanceException:执行DDL错误“

升级到SpringBoot2.7时失败的测试-- "CommandAcceptanceException:执行DDL错误“
EN

Stack Overflow用户
提问于 2022-06-08 13:31:36
回答 1查看 1.8K关注 0票数 2

升级到Boot2.7之后,使用嵌入式H2数据库的集成测试开始失败。

我在日志中看到了这条警告消息,但不太清楚原因或解决方案:

代码语言:javascript
运行
复制
WARN 8053 ---[           main] o.h.t.s.i.ExceptionHandlerLoggedImpl     :GenerationTarget encountered exception accepting command : Error executing DDL "create table user (id bigint generated by default as identity, email varchar(255) not null, name varchar(255), primary key (id))" via JDBC Statement

org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table user (id bigint generated by default as identity, email varchar(255) not null, name varchar(255), primary key (id))" via JDBC Statement
...
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create table [*]user (id bigint generated by default as identity, email varchar(255) not null, name varchar(255), primary key (id))"; expected "identifier"; SQL statement:
create table user (id bigint generated by default as identity, email varchar(255) not null, name varchar(255), primary key (id)) [42001-212]
...

我的User表似乎不是在升级之后创建的,因此我的测试失败了。

EN

回答 1

Stack Overflow用户

发布于 2022-06-08 13:31:36

Boot2.7似乎升级到了它的H2依赖项2.x,这是不向后兼容的,并引入了一些更改:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.7-Release-Notes#h2-21

问题是,User现在是一个关键字/保留词(在我的例子中,H2“迁移到-v2”指南不是很有用;它提到添加了新的关键字,但它没有提供指向:

https://www.h2database.com/html/advanced.html#keywords

因此,我需要做的是使用“引证姓名”来定义实体的表名(似乎我也可以在表注释中使用backticks来代替转义双引号):

代码语言:javascript
运行
复制
@Table(name="\"user\"")
@Entity
public class User {
...

对于这个表,我还必须对我的data.sql文件使用双引号:

代码语言:javascript
运行
复制
INSERT INTO "user"(id, email, name) VALUES(1, 'test@user.com', 'Test User');

注意:迁移指南还提到了使用命令作为解决方法的可能性,但也不鼓励它。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72546596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档