在将Spring Boot从版本2.6.3升级到2.7.3后,我的H2数据库出现了问题(在Spring Boot升级之后,显然H2数据库也得到了升级)。
启动应用程序后,我收到错误:
GenerationTarget encountered exception accepting command : Error executing DDL "create table appa_attributes (id bigint generated by default as identity, name varchar(255), value varchar(4000), primary key (id))" via JDBC Statement org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table appa_attributes (id bigint generated by default as identity, name varchar(255), value varchar(4000), primary key (id))" via JDBC Statement
应用程序.属性:
server.port=8080
spring.mvc.favicon.enabled = false // this in version 2.7 is deprecated
spring.datasource.url=jdbc:h2:mem:testdb
spring.h2.console.enabled=true
spring.h2.console.path=/console/
spring.h2.console.settings.web-allow-others=true
spring.jpa.hibernate.ddl-auto=create-drop
Attribute.java(表定义如下)
@Entity
@Table(name = "appa_attributes")
public class Attribute extends AbstractEntity<Long> implements Comparable<Attribute> {
@Column(length = 255)
private String name;
@Column(length = 4000)
private String value;
//getters and setter
1条答案
按热度按时间z31licg01#
这里的最佳选择是使用类似
@Column(name = "ATT_VALUE", length = 4000)
的名称重命名列,而不需要在Entity中重命名您的字段。或者,您可以通过将
hibernate.globally_quoted_identifiers
设置为true
(在Spring配置中,它将是spring.jpa.properties.hibernate.globally_quoted_identifiers=true
)来强制引用所有标识符。在最坏的情况下,您可以将
;NON_KEYWORDS=USER
添加到h2的JDBC URL,但您应该了解,此设置不是非常可靠,并且可能并不是在所有情况下都有效。