I have a small SpringBoot JPA REST service.
I'm using H2 for a development environment.
I'm using ddl-auto: update
Using a SINGLE table strategy for hierarchical entities.
Simulation of actual code is like below
@Data
@Entity
@NoArgsConstructor
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "TYPE")
public abstract class SuperEntity {
@Id
@GeneratedValue
Long id;
private String property1;
private String property2;
.............
...............
@ManyToOne
private SomeOtherEntity b;
}
There are many Child entities, But one of the entities is like this
@Data
@NoArgsConstructor
@Entity
@DiscriminatorValue("child1")
public class Child1 extends SuperEntity {
@Enumerated(EnumType.STRING)
private CType cType;
private BigDecimal limit;
private BigDecimal x;
private BigDecimal y;
private int z;
.............
...............
}
But at the application startup during DDL execution, I am getting the following exception.
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement
CREATE TABLE SUPER_ENTITY (
.............
...............
LIMIT[*] DECIMAL(19,2),
.............
...............
) "; expected "identifier"; SQL statement:
I mentioned only LIMIT column because this is where * is mentioned by H2 error log. if I just changed the name of the field in Child1 class from limit to creditLimit, all works fine.
what's the problem having a column name limit?
As Alan Hey mentioned, 'limit' is a reserved keyword. So you need to escape it like:
@Column(name = "`limit`")
There are a few more methods. See https://vladmihalcea.com/escape-sql-reserved-keywords-jpa-hibernate/