不能在一个插入空了许多relatioship休眠注释 [英] cannot insert null in one to many relatioship hibernate annotation
问题描述
我有一个类A {B组.....}持有B类为集的引用。它是一对多的关系。
这两个班在甲骨文序。我把级联到所有处于休眠注释。当我保存A级,它让我不能插入空B.a_id错误。 A-ID是不是在我的数据库为空。我如何能坚持这个relatioship。
这是从A-> B的单向关系。表B中A_ID列不能为空。当Hibernate试图保存B类,它不能够找到A_ID值。
块引用>好吧,你尽量让
JoinColumn
非可为空
?@OneToMany
@Cascade({} CascadeType.ALL)
@JoinColumn(NAME =A_ID,可为空= FALSE)
私人设置< B> b:另请参见
- Hibernate的核心参考指南
I have a class A{Set b .....} which holds references of class B as Set. It is one to many relationship. Both class have sequencer in oracle. I put cascade to all in hibernate annotations. When i save class A, it gives me error that cannot insert null B.a_id . A-id is not nullable in my database. How can i persist this relatioship.
解决方案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.
Well, did you try to make the
JoinColumn
nonnullable
?@OneToMany @Cascade({CascadeType.ALL}) @JoinColumn(name="A_ID", nullable=false) private Set<B> b;
See also
- Hibernate Core Reference Guide
这篇关于不能在一个插入空了许多relatioship休眠注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!