不能在一对多关系hibernate注释中插入null [英] cannot insert null in one to many relationship hibernate annotation

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

问题描述

我有一个class A {Set b .....},它将B类的引用保存为Set。这是一对多的关系。
这两个类都有oracle中的音序器。我把所有的级联放在hibernate注释中。当我保存类A时,它给了我错误,无法插入空B.a_id。 A-ID在我的数据库中不可为空。我怎么能坚持这种关系。

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 relationship.

推荐答案


这是从A-> B的单向关系。表B中的a_id列不可为空。当hibernate尝试保存类B时,它无法找到a_id的值。

那么,您是否尝试使 JoinColumn nullable

Well, did you try to make the JoinColumn non nullable?

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



另见




  • Hibernate核心参考指南


    • 6.2.1。集合外键

    • See also

      • Hibernate Core Reference Guide
        • 6.2.1. Collection foreign keys
        • 这篇关于不能在一对多关系hibernate注释中插入null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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