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. 一款我常用到的手机app

    我从初中开始接触电子书,后来渐渐养成了看电子书的习惯.在阅读电子书的过程中自然要接触到各种各样的阅读类的手机app,比如书旗.qq阅读.百度阅读器等等.个人感觉掌阅使用起来好一些. 首先,它的界面很简 ...

  2. 查询正在运行的请求及其后台对应SQL

    SELECT a.event , s.actual_start_date , a.sid, a.serial#, sa.sql_fulltext , sa.sql_text , v.user_conc ...

  3. groovy学习知识

    (1)Groovy是一种基于JVM的敏捷开发语言,它结合了Python.Ruby和Smalltalk的许多强大的特性,Groovy 代码能够与 Java 代码很好地结合,也能用于扩展现有代码.它是一种 ...

  4. linux-linnode满了的提示

    线上有一台web服务器磁盘检测告警了,提示空间不足,登到服务器查看 <ignore_js_op> touch:cannot touch `furm.html': No space left ...

  5. C#编程经验-enum and struct

    enum,store fixed values,use array replace,not use this data-structurestruct,store several variables, ...

  6. .net core 中间件实战

    1.新建一个ASP.NET Core Web Application项目,选择空模板. 2.新建一个类RequestIPMiddleware.cs using Microsoft.AspNetCore ...

  7. 把已经安装到C盘的软件完美移动到D盘

    背景信息 今天早上在安装软件的时候发现C盘爆满,只剩下最后10G了.而我要安装的玩意儿必须装到C盘. 靠清理垃圾文件来解决并不是一个好方法,实际上通常垃圾文件占用很少,而且就算清理了,也还会再出现. ...

  8. import 搜索路径

    来源 http://www.runoob.com/python/python-mysql.html 搜索路径 当你导入一个模块,Python 解析器对模块位置的搜索顺序是: 1.当前目录 2.如果不在 ...

  9. 多端统一框架尝试--Taro

    参考资料 Taro官网Taro GitHubTaro资源汇总Taro-UI 我的demo代码 github地址 Taro介绍和尝试心得 Taro是基于React语法规范开发的多端统一的框架,一套代码可 ...

  10. GC(垃圾处理机制)面试题

    1: 详细解释Java中垃圾收集的主要流程.  垃圾收集主要有两种形式:手工.自动 自动会不定期进行回收,以释放无用的空间 手工调用的是System类中的gc()方法,此方法实际上调用的是Runtim ...