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的更多相关文章

  1. 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(参考资料: ...

  2. 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 ...

  3. Hibernate的一个问题object references an unsaved transient instance - save the transi5

    1 我做了一对多和多对一的双向关联关系,在User这一方@ManyToOne已经设置了级联Cascade,这样在测试程序中保存User时,Group也应该自动保存,为什么会抛出以下的异常: (我是按着 ...

  4. 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 ...

  5. object references an unsaved transient instance - save the transient instance before flushing异常问题处理

    一.异常:org.hibernate.TransientObjectException: object references an unsaved transient instance - save ...

  6. ManyToMany【项目随笔】关于异常object references an unsaved transient instance

    在保存ManyToMany  时出现异常: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.Tran ...

  7. 三大框架常遇的错误:hibernate : object references an unsaved transient instance

    hibernate : object references an unsaved transient instance 该错误是操作顺序的问题,比如: save或update顺序问题---比方学生表和 ...

  8. object references an unsaved transient instance【异常】

    [异常提示] TransientObjectException: object references an unsaved transient instance -save the transient ...

  9. org.unsaved transient instance - save the transient instance before flushing: bug解决方案

    最近开发和学习过程中,遇到很多零碎的知识点,在此简单地记录下: 1.遇如下bug: org.unsaved transient instance - save the transient instan ...

随机推荐

  1. PythonStudy——列表操作 List operatio

    # 1.列表的增删改查 ls = [1, 2, 3] # 查 print(ls) print(ls[1]) # 增 ls.append(0) # 末尾增 print(ls) ls.insert(1, ...

  2. CNN+BLSTM+CTC的验证码识别从训练到部署

    项目地址:https://github.com/kerlomz/captcha_trainer 1. 前言 本项目适用于Python3.6,GPU>=NVIDIA GTX1050Ti,原mast ...

  3. 东芝 B-EV4 打印机 串口打印命令

    最近在做项目时候使用了东芝的B-EV4打印机,在打印Excel时候由于字体太小,导致打印非常模糊.只能通过串口名称发送打印指令进行打印.在做项目的时候查了很多关于B-EV4打印机的资料,和打印命令.资 ...

  4. [转]Servlet的学习之Filter过滤器技术

    本篇将讲诉Servlet中一项非常重要的技术,Filter过滤器技术.通过过滤器,可以对来自客户端的请求进行拦截,进行预处理或者对最终响应给客户端的数据进行处理后再输出. 要想使用Filter过滤器, ...

  5. SVN远程管理

    1.使用远程桌面连接工具,分别填写连接地址和用户名进行连接 2.紧接着进行安全登录. 3.打开VisualSVN Server Manager工具进行显示已经拥有的项目和分配好的群组管理. 这样子就可 ...

  6. AIOps指导

       AIOps代表运维操作的人工智能(Artificial Intelligence for IT Operations), 是由Gartner定义的新类别,Gartner的报告宣称,到2020年, ...

  7. cookie.js插件

    /*! cookiejs v1.0.23 | MIT (c) 2018 kenny wong | https://github.com/jaywcjlove/cookie.js */!function ...

  8. 1、Shiro 安全框架与Spring 整合详解

    Apache Shiro 是一个安全认证框架,和 Spring Security 相比,在于他使用了比较简洁易懂的认证和授权方式.其提供的 native-session(即把用户认证后的授权信息保存在 ...

  9. tfs项目管理

    同一个地址下有多个项目,但同一个文件只能映射一次.有两种方式: 1.只添加一次映射,即只给根目录添加映射,如下图,这样西面的具体的项目就不需要挨个添加了. . 2.每个项目挨个添加映射,使用这种方式要 ...

  10. [Oracle,2018-03-01] oracle常用函数

    最近经常用到一些oracle中的函数,今天就总结一些常用的: 一.单行函数 只处理单个行,并且为每行返回一个结果. 1.字符函数 (1)concat(str1,str2)字符串拼接函数 select ...