java - TransientPropertyValueException: object references an unsaved transient instance - 在刷新之前保存瞬态实例:
问题描述
@Entity
@Table(name="tbl_name")
public class Test extends BaseEntity {
@OneToOne( fetch = FetchType.LAZY)
@JoinColumn(name = "ALL_ORG_MST_SECTION_ID",nullable = true)
private AllOrgMst allOrgMstSection;
@OneToOne(fetch = FetchType.LAZY )
@JoinColumn(name = "ALL_ORG_MST_SUB_SECTION_ID",nullable = true)
private AllOrgMst allOrgMstSubSection;
}
这是模型。当我插入此模型时,一个对象为空值,然后显示错误
邮递员对象通行证
{
"allOrgMstSection": {
"id": 23
},
"allOrgMstSubSection": {
"id": null
}
}
@Autowired
private TestRepository testRepository;
@Override
public Test save2(Test entity) {
return testRepository.save(entity);
}
在 baseEntity 中有 Id
解决方案
只是简单地解决了这个问题
{
"allOrgMstSection": {
"id": 23
},
"allOrgMstSubSection": null,
}
推荐阅读
- c++ - 有没有办法定义动态数组而不确定它的大小
- python - 如何使用 2 个或更多参数创建自定义 Flask CLI 命令?
- kotlin - Micronaut Kotlin:休息控制器不起作用
- flutter - Flutter 无法连接到 VSCode 中的模拟器。等待来自 Flutter 的连接
- excel - 检查匹配项并将数据从外部源导入特定单元格
- java - 在 Android 中使用 JDBC 优化 mysql DB 执行
- php - 图像优化 laravel
- python - 员工详情
- excel - 如果满足条件,请选择要复制并粘贴到另一个单元格中的范围
- html - 无法使导航菜单居中