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

  这主要是在ManyToOne级联操作时遇到,比如new了一个新对象,在未保存之前将它保存进了一个新new的对象(也即不是持久态)。

  解决办法是在保存或更新之前把这个对象查出来(这样就是一个持久态)。

  解决办法是将many-to-one的级联设为: cascade="save-update,persist"

  四种 CASCADE 类型:
    * PERSIST:持久保存拥有方实体时,也会持久保存该实体的所有相关数据。
    * MERGE:将分离的实体重新合并到活动的持久性上下文时,也会合并该实体的所有相关数据。
    * REMOVE:删除一个实体时,也会删除该实体的所有相关数据。
    * ALL:以上都适用。

二、异常1:not-null property references a null or transient value
  解决方法:将“一对多”关系中的“一”方,not-null设置为false

  异常2:org.hibernate.TransientObjectException: object references an unsaved transient instance
  解决方法:cascade="save-update,persist"

  异常3:org.hibernate.QueryException: could not resolve property
  解决方法:"from Category category where category.userID = :userID"修改为"from Category category where userID = :userID"或者"from Category category where category.user.id =
:userID"

  异常4:could not initialize proxy - the owning Session was closed
  解决方法:设置lazy为false

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. object references an unsaved transient instance save the transient instance before flushing

    object references an unsaved transient instance save the transient instance before flushing 对象引用未保存的 ...

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

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

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

  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. GIS专业分析方法(待更新)

    遗传算法 核密度估计 http://blog.163.com/zhuandi_h/blog/static/1802702882012111092743556/ http://blog.csdn.net ...

  2. [洛谷P4588][TJOI2018]数学计算

    题目大意:有一个数$x$和取模的数$mod$,初始为$1$,有两个操作: $m:x=x\times m$并输出$x\% mod$ $pos:x=x/第pos次操作乘的数$(保证合法),并输出$x\%m ...

  3. tcp nio 远程主机强迫关闭了一个现有的连接

    import java.io.IOException; import java.net.InetSocketAddress; import java.net.ServerSocket; import ...

  4. (原创)Linux下MySQL 5.5/5.6的修改字符集编码为UTF8(彻底解决中文乱码问题)

    « CloudStack+XenServer详细部署方案(10):高级网络功能应用 (总结)CentOS Linux 5.x在GPT分区不能引导的解决方法 » 2013-1 11 (原创)Linux下 ...

  5. 飞思卡尔 HCS12(x) memory map解说

    对于用MCU的人来说,不一定要明白HCS12(x) memory map的机制和联系.因为如果没有系统地学习操作系统和编译原理之类的课程,确实有些难度.并且,对于DG128 XS128这样的MCU,默 ...

  6. js date扩展方法

    /* File Created: 四月 28, 2015 */ //日期加上天数得到新的日期 //dateTemp 需要参加计算的日期,days要添加的天数,返回新的日期,日期格式:YYYY-MM-D ...

  7. 理想中的SQL语句条件拼接方式 (二)

    问题以及想要的效果,不重复叙述,如果需要的请先看 理想中的SQL语句条件拼接方式 . 效果 现在有2个类映射数据库的2张表,结构如下: public class User { public int U ...

  8. 编写COOL编译器

    Coursera上面有Stanford的课程“Compilers”,该课程使用“龙书”作为参考书,并有一个编程项目,完成一个完整的编译器.这个编译器支持的语言称为COOL,是一个面向对象的用于教学的语 ...

  9. 我们为什么需要 lock 文件

    前言 从 Yarn 横空出世推出 lock 文件以来,已经两年多时间了,npm 也在 5.0 版本加入了类似的功能,lock 文件越来越被开发者们接收和认可.本篇文章想从前端视角探讨一下我们为什么需要 ...

  10. django的url匹配流程

    URL匹配流程(路由解析顺序): URL匹配流程说明 域名.端口.端口后的 /,以及查询字符串(问号后面的键值参数)不参与匹配 先到项目下的 urls.py 进行匹配,再到应用的 urls.py 匹配 ...