【发布时间】:2018-01-29 09:18:10
【问题描述】:
我有一个基于休眠策略 SINGLE_TABLE 的实体层次结构,我在 application.yml 中设置了 ddl-auto=update。
当我使用 h2db 运行测试时,我得到“NULL not allowed for column ”。
这是我的映射:
==================
Shape
|--> Square
|--> Cube
==================
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "IS_SOLID", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue(value = "-1")
public abstract class Shape{
...
}
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "null")
public class Square extends Shape{
...
}
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorValue(value = "1")
public class Cube extends Shape{
...
}
我需要将 null 作为 discriminatorValue 设置为一个子类。
当ddl-auto=update 指令创建形状表时,它将鉴别器列设置为not null,所以我得到“NULL not allowed for column ”。
有没有办法使用 ddl-auto 强制鉴别器列可以为空?
【问题讨论】:
-
你找到解决办法了吗?
-
不,不是注释。仅针对我的特定场景的解决方法:我在 junit 测试的“之前”方法中编写了一个“更改表”,以删除描述符列中的
not null。
标签: hibernate spring-boot h2db