object references an unsaved transient instance save the transient instance before flushing
object references an unsaved transient instance save the transient instance before flushing
对象引用未保存的瞬态实例,在刷新前保存瞬态实例
错误实例:
mortgageInfoDTO MortgagePersonDTO两者关系 MortgagePersonDTO中包含mortgageInfoDTO 对象
前提:mortgageInfoDTO MortgagePersonDTO 已存在数据库中 且新建相同的数据对象(临时对象)
mortgageInfoDTO = mortgageInfoDAO.saveOrUpdate(mortgageInfoDTO);
list = mortgagePersonDAO.createBatch(MortgagePersonDTOList);
解决方法:
错误原因:
在调用hibernate存储数据时,需要将数据库中表对应的持久类对象作为参数传递。如果这时的对象中有其他的表字段属性并且是引用对象类型,那么这个属性必须是持久态或者是null的,瞬时态和脱管态都会报错。我这次报错就是因为在订单对象中包含了其他对象,并且这些对象不为null。
如果包含的对象的数据用不到的话,最简便的解决办法就是把包含的对象全部置为null。
如果用得到对象中的数据,那么调用持久层的方法重新查询出对应的对象,此对象此时为持久态,在重新赋值到要保存的对象中即可。
修改方法:
mortgageInfoDTO = mortgageInfoDAO.saveOrUpdate(mortgageInfoDTO);
MortgageInfoDTO mor = mortgageInfoDAO.findById(mortgageInfoId);
for (MortgagePersonDTO personDTO : MortgagePersonDTOList) {
personDTO.setMortgageInfoDTO(mor);
}
list = mortgagePersonDAO.createBatch(MortgagePersonDTOList);
给personDTO赋予一个持久化的对象去替换那个临时对象,然后在提交事务。
object references an unsaved transient instance save the transient instance before flushing的更多相关文章
- object references an unsaved transient instance - save the transient instance before flushing错误
异常1:not-null property references a null or transient value解决方法:将“一对多”关系中的“一”方,not-null设置为false(参考资料: ...
- ERROR org.hibernate.internal.SessionImpl - HHH000346: Error during managed flush [object references an unsaved transient instance - save the transient instance before flushing: cn.itcast.domain.Custom
本片博文整理关于Hibernate中级联策略cascade和它导致的异常: Exception in thread "main" org.hibernate.TransientOb ...
- Hibernate的一个问题object references an unsaved transient instance - save the transi5
1 我做了一对多和多对一的双向关联关系,在User这一方@ManyToOne已经设置了级联Cascade,这样在测试程序中保存User时,Group也应该自动保存,为什么会抛出以下的异常: (我是按着 ...
- object references an unsaved transient instance - save the transient instance before flushing: com.jspxcms.core.domain.ScTeam
object references an unsaved transient instance - save the transient instance before flushing: com.j ...
- object references an unsaved transient instance - save the transient instance before flushing异常问题处理
一.异常:org.hibernate.TransientObjectException: object references an unsaved transient instance - save ...
- ManyToMany【项目随笔】关于异常object references an unsaved transient instance
在保存ManyToMany 时出现异常: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.Tran ...
- 三大框架常遇的错误:hibernate : object references an unsaved transient instance
hibernate : object references an unsaved transient instance 该错误是操作顺序的问题,比如: save或update顺序问题---比方学生表和 ...
- object references an unsaved transient instance【异常】
[异常提示] TransientObjectException: object references an unsaved transient instance -save the transient ...
- org.unsaved transient instance - save the transient instance before flushing: bug解决方案
最近开发和学习过程中,遇到很多零碎的知识点,在此简单地记录下: 1.遇如下bug: org.unsaved transient instance - save the transient instan ...
随机推荐
- 依据Axis2官网的高速入门英文文档总结
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/ksdb0468473/article/details/29918027 首先在Eclipse中创建一 ...
- Spring/Spring MVC
90.为什么要使用 spring? 答:spring是一个开源框架,是个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架 方便结构简化开发 AOP编码的支持 声明式事物的支持 方便程序的测试 ...
- html总结2
(1)选择器: 1.标签选择器:用于修饰同类HTML标签的共性风格 <style type="text/css"> li{ color:red; font-size:2 ...
- find查找文件的时间问题
很多细节方面的东西没有到真正用的时候,是觉察不出来的,因为这个时间的问题出了问题,现在好好理一下,这个find的时间很容易就搞混了,一段时间不用,也忘了,也反映出来了自己的基础知识不是很牢固啊 f ...
- UDP广播包
一,广播地址: 广播地址是专门用于同时向网络中所有工作站进行发送的一个地址.在使用TCP/IP 协议的网络中,主机号为全1的IP地址为广播地址.例如,对于 :192.168.199.0(掩码:255. ...
- 文件-- 字节相互转换(word、图片、pdf...)
方式一: /// <summary> /// word文件转换二进制数据(用于保存数据库) /// </summary> /// <param name="wo ...
- 文件管理 - Ring3创建目录
//多字符集 #include "stdafx.h" #include <Windows.h> #include <iostream> using name ...
- android selector shape 使用
先上效果图 message_toolbar_left_bg_selector <?xml version="1.0" encoding="utf-8"?& ...
- Nios II Host-Based File System
Nios II Host-Based File System 允许运行在Nios II的程序,在Debug模式下,通过Altera download cable来读写PC上当前工程目录下(及其子目录) ...
- Vue中table表头合并的用法
<div class="panel-container"> <div> <table class="table-head" wid ...