Spring JPA Hibernate 无法自动生成 Id H2 table
Spring JPA Hibernate Fails To Auto-generate Id H2 table
我在尝试使用自动生成的 ID 创建 table 时遇到异常:
org.hibernate.tool.schema.spi.CommandAcceptanceException: "Error executing DDL "create table seat (id bigint not null, description varchar(255), num integer not null, price decimal(19,2), row char(255) not null, primary key (id))" via JDBC Statement".
生成的 SQL 似乎无法识别“@GeneratedValue(strategy = GenerationType.TABLE)”注释。看起来这是 Hibernate 或适配器的一个非常普遍的问题。
现在,在您将此问题作为重复问题丢弃之前,我已经 q/a 浏览了所有具有类似问题的问题并尝试了那里建议的所有解决方案。我也尝试自己生成 Id 密钥并尝试将 spring.jpa.properties.hibernate.hbm2ddl.auto 设置为 'delete-create'
application.properties
spring.datasource.driverClassName = org.h2.Driver
spring.datasource.username = sa
spring.datasource.password =
spring.jpa.properties.hibernate.hbm2ddl.auto=update
实体Class
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) ))
}
}
}
我尝试过的事情:
- strategy=GenerationType.AUTO 更改为 .SEQUENCE 和 .TABLE
- 将此添加到 application.properties:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
我尝试自己生成 Id 但没有成功。我一定是遗漏了一些东西,因为我是 Kotlin 新手,Spring Boot 和 Hibernate,但在这里碰壁了。请指教!
jdk-14, Spring Boot v2.2.6.RELEASE,
使用方言:org.hibernate.dialect.H2Dialect
这里是问题val row: Char
,ROW是SQL中的保留字。改变那个 var
我在尝试使用自动生成的 ID 创建 table 时遇到异常:
org.hibernate.tool.schema.spi.CommandAcceptanceException: "Error executing DDL "create table seat (id bigint not null, description varchar(255), num integer not null, price decimal(19,2), row char(255) not null, primary key (id))" via JDBC Statement".
生成的 SQL 似乎无法识别“@GeneratedValue(strategy = GenerationType.TABLE)”注释。看起来这是 Hibernate 或适配器的一个非常普遍的问题。
现在,在您将此问题作为重复问题丢弃之前,我已经 q/a 浏览了所有具有类似问题的问题并尝试了那里建议的所有解决方案。我也尝试自己生成 Id 密钥并尝试将 spring.jpa.properties.hibernate.hbm2ddl.auto 设置为 'delete-create'
application.properties
spring.datasource.driverClassName = org.h2.Driver
spring.datasource.username = sa
spring.datasource.password =
spring.jpa.properties.hibernate.hbm2ddl.auto=update
实体Class
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) ))
}
}
}
我尝试过的事情: - strategy=GenerationType.AUTO 更改为 .SEQUENCE 和 .TABLE - 将此添加到 application.properties:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
我尝试自己生成 Id 但没有成功。我一定是遗漏了一些东西,因为我是 Kotlin 新手,Spring Boot 和 Hibernate,但在这里碰壁了。请指教!
jdk-14, Spring Boot v2.2.6.RELEASE, 使用方言:org.hibernate.dialect.H2Dialect
这里是问题val row: Char
,ROW是SQL中的保留字。改变那个 var