下面是一个带有columnDefinition
属性的简单实体:
@Entity
@Table(name = "simple_user")
public class SimpleUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(columnDefinition = "varchar(64) NOT NULL default 'John'")
private String nickname;
}
字符串
第一次运行后,创建一个表,如下所示:
2023-06-24 18:22:20.380 | INFO | restartedMain | p6spy | 21 ms | statement | create table simple_user (id serial not null, nickname varchar(64) NOT NULL default 'John', primary key (id)) | logSQL(Slf4JLogger.java:60)
2023-06-24 18:22:20.383 | INFO | restartedMain | p6spy | 2 ms | statement | comment on table simple_user is 'User' | logSQL(Slf4JLogger.java:60)
2023-06-24 18:22:20.387 | INFO | restartedMain | p6spy | 2 ms | statement | comment on column simple_user.nickname is 'nickname' | logSQL(Slf4JLogger.java:60)
型
第二次运行后,没有任何修改,我得到一些错误:
2023-06-24 18:25:25.520 | INFO | restartedMain | c.z.h.HikariDataSource | HikariPool-1 - Start completed. | getConnection(HikariDataSource.java:123)
2023-06-24 18:25:26.079 | INFO | restartedMain | p6spy | 22 ms | statement | select * from information_schema.sequences | logSQL(Slf4JLogger.java:60)
2023-06-24 18:25:26.106 | INFO | restartedMain | o.h.b.i.BytecodeProviderInitiator | HHH000021: Bytecode provider name : bytebuddy | buildBytecodeProvider(BytecodeProviderInitiator.java:53)
2023-06-24 18:25:27.239 | INFO | restartedMain | o.h.e.t.j.p.i.JtaPlatformInitiator | HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] | initiateService(JtaPlatformInitiator.java:51)
2023-06-24 18:25:27.272 | INFO | restartedMain | p6spy | 3 ms | statement | select * from information_schema.sequences | logSQL(Slf4JLogger.java:60)
2023-06-24 18:25:27.315 | INFO | restartedMain | p6spy | 5 ms | statement | alter table if exists simple_user alter column nickname set data type varchar(64) NOT NULL default 'John' | logSQL(Slf4JLogger.java:60)
2023-06-24 18:25:27.317 | WARN | restartedMain | o.h.t.s.i.ExceptionHandlerLoggedImpl | GenerationTarget encountered exception accepting command : Error executing DDL "alter table if exists simple_user alter column nickname set data type varchar(64) NOT NULL default 'John'" via JDBC [ERROR: syntax error at or near "NOT"
Position: 83] | handleException(ExceptionHandlerLoggedImpl.java:27)
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table if exists simple_user alter column nickname set data type varchar(64) NOT NULL default 'John'" via JDBC [ERROR: syntax error at or near "NOT"
Position: 83]
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:92)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:574)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:514)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.migrateTable(AbstractSchemaMigrator.java:333)
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:84)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:232)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:117)
型
似乎columnDefinition又被执行了。这种行为只发生在Sping Boot 3.1.1中。
在Sping Boot 3.0.x和2.6.x中一切正常。
这是一个bug还是一个设计?
1条答案
按热度按时间0dxa2lsx1#
你试过这个吗?
字符串