Java Spring JPA Hibernate无法自动生成Id H2表

Java Spring JPA Hibernate无法自动生成Id H2表,java,hibernate,spring-boot,jpa,h2,Java,Hibernate,Spring Boot,Jpa,H2,尝试创建具有自动生成Id的表时出现异常: org.hibernate.tool.schema.spi.CommandAcceptanceException:“执行DDL时出错”通过JDBC语句“创建表席位(id bigint not null,description varchar(255),num integer not null,price decimal(19,2),row char(255)not null,primary key(id))” 生成的SQL似乎无法识别“@Generate

尝试创建具有自动生成Id的表时出现异常:

org.hibernate.tool.schema.spi.CommandAcceptanceException:“执行DDL时出错”通过JDBC语句“创建表席位(id bigint not null,description varchar(255),num integer not null,price decimal(19,2),row char(255)not null,primary key(id))”

生成的SQL似乎无法识别“@GeneratedValue(strategy=GenerationType.TABLE)”注释。看起来这是Hibernate或Adapter的常见问题

现在,在你把这个问题当作一个重复的问题来处理之前,我已经完成了一个类似问题的所有问答,并尝试了这里建议的所有解决方案。我还尝试自己生成Id密钥,并尝试将spring.jpa.properties.hibernate.hbm2ddl.auto设置为“delete create”

应用程序属性

spring.datasource.driverClassName = org.h2.Driver
spring.datasource.username = sa
spring.datasource.password =
spring.jpa.properties.hibernate.hbm2ddl.auto=update
import java.math.BigDecimal
import javax.persistence.*

@Entity
data class Seat(
@Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id")
                val id: Long,
                val row: Char,
                val num: Int,
                val price: BigDecimal,
                val description: String) {
    override fun toString(): String = "Seat $row-$num $$price ($description)"
}
实体类

spring.datasource.driverClassName = org.h2.Driver
spring.datasource.username = sa
spring.datasource.password =
spring.jpa.properties.hibernate.hbm2ddl.auto=update
import java.math.BigDecimal
import javax.persistence.*

@Entity
data class Seat(
@Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id")
                val id: Long,
                val row: Char,
                val num: Int,
                val price: BigDecimal,
                val description: String) {
    override fun toString(): String = "Seat $row-$num $$price ($description)"
}
服务构造函数

constructor() {
        ...
        for (row in 1..15) {
            for (num in 1..36) {
                hiddenSeats.add(Seat(0, (row+64).toChar(), num, getPrice(row,num), getDescription(row,num) ))
            }
        }
    }
我尝试过的事情: -策略=GenerationType.AUTO更改为.SEQUENCE和.TABLE -将此添加到application.properties:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
我试图自己生成Id,但没有成功。我一定是错过了什么,因为我是新的科特林、春靴和冬眠,但在这里撞到了墙。请告知

jdk-14,Spring Boot v2.2.6.0版本,
使用方言:org.hibernate.dialogue.h2dialogue

这里有一个问题
val row:Char
,row是SQL中的保留字。更改var

这里是问题
val行:Char
,行是SQL中的保留字。改变这个var

它在SQL中不是保留字,但在H2中显然是保留字,因为我能够使它在mySql中正常工作。无论如何,我会把它标记为答案,因为你们已经足够接近了。现在很好奇,演示者是如何在教程中工作的。。。无论如何谢谢你!它在SQL中不是保留字,但在H2中显然是保留字,因为我能够使它在mySql中正常工作。无论如何,我会把它标记为答案,因为你们已经足够接近了。现在很好奇,演示者是如何在教程中工作的。。。无论如何谢谢你!