无法在一对多关系休眠注释中插入空值 [英] cannot insert null in one to many relationship hibernate annotation

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

问题描述

我有一个类 A{Set b .....} 它将类 B 的引用保存为 Set.这是一对多的关系.这两个类在 oracle 中都有音序器.我将级联放在休眠注释中.当我保存 A 类时,它给了我无法插入 null 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 列不可为空.当休眠尝试保存 B 类时,它无法找到 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?

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.集合外键
    • 这篇关于无法在一对多关系休眠注释中插入空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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