一、异常: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. [SDOI2015][bzoj3990] 序列 [搜索]

    题面 传送门 思路 首先,这道题目有一个非常显然(但是我不会严格证明,只能意会一下)的结论:一个合法的操作序列中,任意两个操作是可以互换的 那么,这个结论加上本题极小的数据范围,为什么不搜索一下呢? ...

  2. 【CZY选讲·一道图论好题】

    题目描述 LYK有一张无向图G={V,E},这张无向图有n个点m条边组成.并且这是一张带权图,不仅有边权还有点权.LYK给出了一个子图的定义,一张图G'={V',E'}被称作G的子图,当且仅当: · ...

  3. Location of ESXi 5.1 log files

    Purpose This article provides the default location of log files on an ESXi 5.1 host. For other produ ...

  4. java:网络编程(InetAddress,InetSocketAddress,URL,TCP(Socket与SeverSocket),TCP与UDP的区别)

    InerAddress: /**IP地址:在网络上唯一标示一台计算机 * 端口号:标示计算机上不同的应用程序 * java.net.InetAddress类:此类表示互联网协议 (IP) 地址. * ...

  5. bzoj3638 Cf172 k-Maximum Subsequence Sum

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3638 [题解] 看到k<=20就感觉很py了啊 我们用一棵线段树维护选段的过程,能选到 ...

  6. win8启用.net framework3.5方法

    管理员命令下执行dism.exe /online /enable-feature /featurename:NetFX3 /Source:L:\sources\sxs

  7. mysql-\g和\G的作用

    \g 的作用是分号和在sql语句中写’;’是等效的 \G 的作用是将查到的结构旋转90度变成纵向(可以将一个很长的行转为好看的格式) 这两个只能在DOS窗口使用,可视化工具中不能使用. 例如:

  8. QML与Qt C++ 交互机制探讨与总结(转)

    原文转自 https://www.cnblogs.com/aoldman/p/4103510.html 介绍 QML和 C++对象可以通过,signals,slots和 属性修改进行交互.对于一个C+ ...

  9. matlab sqlite

    转自: http://www.douban.com/note/359606646/和http://blog.csdn.net/yinxing408033943/article/details/7677 ...

  10. (二十)linux中i2c的ioctl,write,read函数的使用

    一.ioctl函数的使用:原型:struct ioctl(struct file *file,unsigned int cmd,unsigned long arg);cmd有I2C_SLAVE,I2C ...