Reputation: 690
I'm getting an exception when trying to create a table with auto-generated Id:
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".
It looks like the generated SQL doesn't recognize '@GeneratedValue(strategy = GenerationType.TABLE)' annotation. Looks like it's a very common problem with either Hibernate or adaptor.
Now, before you discard this question as a duplicate, I've gone through all q/a with a similar problem and tried all solutions suggested there. I've also tried to generate Id keys myself and tried to set spring.jpa.properties.hibernate.hbm2ddl.auto to 'delete-create'
application.properties
spring.datasource.driverClassName = org.h2.Driver
spring.datasource.username = sa
spring.datasource.password =
spring.jpa.properties.hibernate.hbm2ddl.auto=update
Entity 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)"
}
Service Constructor
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) ))
}
}
}
Things I tried: - strategy=GenerationType.AUTO change to .SEQUENCE and .TABLE - add this to application.properties:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
I tried to generate the Id myself but to no success. I must be missing something as I'm new Kotlin, Spring Boot and Hibernate, but hit the wall here. Please advise!
jdk-14, Spring Boot v2.2.6.RELEASE, Using dialect: org.hibernate.dialect.H2Dialect
Upvotes: 1
Views: 1397
Reputation: 56
Here is the problem val row: Char
, ROW is a reserved word in SQL. change that var
Upvotes: 3