我有一个类 A{Set b .....} 将类 B 的引用保存为 Set。它是一对多的关系。 这两个类在 oracle 中都有音序器。我在 hibernate 注释中将级联全部放入。当我保存 A 类时,它给了我无法插入 null B.a_id 的错误。 A-id 在我的数据库中不可为空。我怎样才能维持这种关系。
最佳答案
This is a unidirectional relationship from A->B. a_id column in table B is not nullable. When hibernate tries to save class B, it not able to find value for a_id.
好吧,您是否尝试过使 JoinColumn
非 nullable
?
@OneToMany
@Cascade({CascadeType.ALL})
@JoinColumn(name="A_ID", nullable=false)
private Set<B> b;
另见
- Hibernate 核心引用指南
关于java - 不能在一对多关系 hibernate 注释中插入空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3724719/