object references an unsaved transient instance - save the transient instance before flushing异常问题处理
一、异常: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异常问题处理的更多相关文章
- 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 ...
- object references an unsaved transient instance save the transient instance before flushing
object references an unsaved transient instance save the transient instance before flushing 对象引用未保存的 ...
- 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 ...
- 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 ...
随机推荐
- CS Academy Distinct Neighbours(经典dp)
CS Academy Distinct Neighbours(经典dp) 题意: 求相邻无相同数字的合法的排列数 题解: 题解 先将相同的数字分为一类,假设共有n组 定义\(dp[i][j]\)表示前 ...
- 【CZY选讲·逆序对】
题目描述 LYK最近在研究逆序对. 这个问题是这样的. 一开始LYK有一个2^n长度的数组ai. LYK有Q次操作,每次操作都有一个参数k.表示每连续2^k长度作为一个小组.假设 n=4,k= ...
- 搭建自己的YUM源HTTP服务器
createrepo是linux下的创建仓库的软件包.create是创建的意思,repo是repository的缩写,是仓库的意思.yum(Yellowdog Updater,Modified)主要的 ...
- matlab sqlite
转自: http://www.douban.com/note/359606646/和http://blog.csdn.net/yinxing408033943/article/details/7677 ...
- Centos 6.3 nginx代理配置
1. 查看nginx所在位置 $ nginx -t /etc/nginx/nginx.conf 2. 配置 user nobody; #启动服务的用户 worker_processes ; err ...
- MPchartAnadroid的对比柱状图
1.导入三方jar包(可参照) MPAndroidChart(GitHub上优秀得图表功能库) MPAndroidChart常见设置属性(一)——应用层 2.布局activity_main.xml(这 ...
- jquery做一个表单验证
正则表达式的写法: var re=new RegExp('规则', '可选参数');var re=/规则/参数;(这个最常用) 正则表达式的规则 和其他语言的正则表达式规则一样,可以参考我的另一边博文 ...
- .apache.commons.io 源代码学习(一)
java的初学者,准备通读各种高水平源代码,提升能力. 为了避免自己的惰性,写博客. 版本:2.5 开发平台:netbeans. 今天是第一天,网上先看个例子:http://www.importnew ...
- 关于delphi编程的网络文件夹复制的代码精要
首先必须引用windows api函数库 shellapi ***************************以下为复制文件夹的代码******************************** ...
- [BZOJ1821][JSOI2010]Group 部落划分 Group 最小生成树 贪心
1821: [JSOI2010]Group 部落划分 Group Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2943 Solved: 1390[S ...