【问题标题】:hibernate one to many mapping bidirectional merge休眠一对多映射双向合并
【发布时间】:2018-06-12 12:56:59
【问题描述】:

我有两张如下表。父子关系。

父表:

parent_id 是自动生成的主键

子表:

parent_idchild_id 是主键,parent_id 是外键

当我尝试在主表中插入新行时,子表也会插入(工作正常)。当我尝试使用合并操作更新父表时,在子表中无法插入新行但能够更新现有行并出现以下错误。

无法将值 NULL 插入列parent_id,表 Test.Sample.child;列不允许空值。

插入失败。

【问题讨论】:

  • 请添加相关代码

标签: hibernate


【解决方案1】:

尝试使用

 cascade=ALL 

根据您的引用映射进行注释。

点击此处了解更多详情。 What is the difference between persist() and merge() in Hibernate?

注意:如果您提供映射和示例使用场景,您的问题可以得到更清楚的回答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    相关资源
    最近更新 更多