【发布时间】:2020-02-04 17:43:04
【问题描述】:
我有一个小型 SpringBoot JPA REST 服务。
我将 H2 用于开发环境。
我正在使用ddl-auto: update
对分层实体使用单表策略。
实际代码模拟如下
@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;
}
有很多子实体,但是其中一个实体是这样的
@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;
.............
...............
}
但在 DDL 执行期间应用程序启动时,我收到以下异常。
Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement
CREATE TABLE SUPER_ENTITY (
.............
...............
LIMIT[*] DECIMAL(19,2),
.............
...............
) "; expected "identifier"; SQL statement:
我只提到了 LIMIT 列,因为这是 H2 错误日志提到 * 的地方。 如果我只是将 Child1 类中的字段名称从 limit 更改为 creditLimit,一切正常。
列名限制有什么问题?
【问题讨论】:
-
因为 limit 是保留关键字(限制选择返回的记录数)。 razorsql.com/articles/h2_limit_rows.html
-
我相信我应该已经看到了。感谢您指出。
标签: hibernate spring-boot spring-data-jpa h2 create-table