java - Spring java一对一关系将实体重新分配给所有者
问题描述
我有一个与 B 一对一相关的实体 A。我创建了一个外键:A.b_id <==> B.id
和
A { @OneToOne(orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER) @JoinColumn(name = "b_id") private B b; }
在某些时候,我会做 A.setB(new B());
但后来我希望能够将其更改为 => A.setB(new B2());
这样做时,我收到以下错误:
update A set ....., b_id=? where id=? []; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
知道我错过了什么吗?
b_id
有一个不为空的约束。
映射看起来像
A {
@OneToOne(orphanRemoval = true, cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
@JoinColumn(name = "b_id")
private B b;
}
解决方案
推荐阅读
- angular - 打字稿没有正确投射
- asp.net-web-api - Kafka 生产者 - 与代理的多个连接与单个全局连接
- javascript - 从 eventlistener 'keyup' 获取嵌套的 li
- php - 如何将 putString 与 firebase-php 库一起使用?
- firebase - 如何在 Firebase 和 Vue.js 中设置电子邮件验证
- c# - 为枚举创建一个通用的 dbset 列表
- sql - 如何阻止任何人向 Postgres 9.6 中的几个表添加列?
- c# - 写入 Serilog 日志文件时如何触发事件?
- java - 解析错误 com.parse.ParseRequest$ParseRequestException: i/o 失败
- reactjs - 我想在 react-table 列的单元格内创建一个按钮