不能在一个插入空了许多relatioship休眠注释 [英] cannot insert null in one to many relatioship hibernate annotation

查看:155
本文介绍了不能在一个插入空了许多relatioship休眠注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类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:

另请参见

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 non nullable?

@OneToMany 
@Cascade({CascadeType.ALL}) 
@JoinColumn(name="A_ID", nullable=false)
private Set<B> b;

See also

这篇关于不能在一个插入空了许多relatioship休眠注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆