Spring Boot JPA为MySQL8生成SQL时columnDefinition语法错误问题
Spring Boot JPA生成MySQL8数据表时columnDefinition语法异常问题
问题场景
使用Spring Boot JPA生成MySQL8数据表,常规场景运行正常,但在@Column注解中使用columnDefinition属性时触发SQL语法错误。
代码示例
@Column(columnDefinition = "boolean default false") private Boolean example;
曾尝试将boolean替换为TINYINT,但MySQL8本身原生支持boolean类型,问题并未解决。
报错信息
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
boolean default falseat line 5
生成的错误SQL语句
create table `exampleTable` ( `id` bigint not null auto_increment, `example` `boolean default false`, primary key (`id`) )
可见example字段的类型定义部分被错误添加了反引号,导致SQL语法不合法。
问题根源
该问题是由于全局标识符自动引用配置错误地将columnDefinition中的字段类型内容也包裹了反引号,进而生成了不符合语法规范的SQL语句。
内容的提问来源于stack exchange,提问作者Jasper Houben
相关产品推荐
相关产品推荐

