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
(参考资料:http://www.thearcmind.com/confluence/pages/viewpage.action?pageId=212)
异常2:org.hibernate.TransientObjectException: object references an unsaved transient instance
解决方法:cascade="save-update,persist"
(参考资料:http://www.laliluna.de/254.html)
异常3:org.hibernate.QueryException: could not resolve property
解决方法:"from Category category where category.userID = :userID"修改为"from Category category whereuserID = :userID"或者"from Category category where category.user.id = :userID"
(参考资料:http://www.laliluna.de/277.html)
异常4:could not initialize proxy - the owning Session was closed
解决方法:设置lazy为false
(参考资料:http://forum.springframework.org/showthread.php?t=27993)
异常2我在应用中碰到了这样的问题:
有三个表:userInfo deptmentInfo role
userInfo 与deptmentInfo为many to one
userInfo 与role为many to one
下面为保存UserInfo对象时的代码:
DeptmentInfo dept = new DeptmentInfo();
dept.setDeptName(deptName);
Role role = new Role();
role.setRoleName(roleName);
UserInfo user = new UserInfo();
user.setUserName(userName);
user.setUserSex(userSex);
user.setDuty(duty);
user.setPhone(phone);
user.setMobileNum(mobileNum);
user.setEmail(email);
user.setQq(qq);
user.setMsn(msn);
user.setAdress(adress);
user.setDeptmentInfo(dept);
user.setRole(role);
dao.save(user);
执行时有错:org.hibernate.TransientObjectException: object references an unsaved transient instance
于是改了UserInfo.hbm.xml的一些地方
如下:
<many-to-one name="role" class="com.oa.domain.Role"
cascade="save-update,persist" fetch="select">
<column name="ROLE_ID" precision="22" scale="0" />
</many-to-one>
<many-to-one name="deptmentInfo"
class="com.oa.domain.DeptmentInfo" cascade="save-update,persist"
fetch="select">
<column name="DEPT_ID" precision="22" scale="0" />
</many-to-one>
加了上面红色部分的,就OK了,能保存了。
object references an unsaved transient instance - save the transient instance before flushing错误的更多相关文章
- 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 ...
- object references an unsaved transient instance - save the transient instance before flushing异常问题处理
一.异常:org.hibernate.TransientObjectException: object references an unsaved transient instance - save ...
- 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 ...
随机推荐
- MVVM架构~Knockoutjs系列之text,value,attr,visible,with的数据绑定
返回目录 Knockoutjs是微软mvc4里一个新东西,用这在MVC环境里实现MVVM,小微这次没有大张旗鼓,而是愉愉的为我们开发者嵌入了一个实现MVVM的插件,这下面的几篇文章中,我和大家将一起去 ...
- PHP数据库操作:使用ORM
之前我发了一篇博文PHP数据库操作:从MySQL原生API到PDO,向大家展示PHP是如何使用MySQL原生API.MySQLi面向过程.MySQLi面向对象.PDO操作MySQL数据库的.本文介绍如 ...
- Atitit java jsp 新的tag技术
Atitit java jsp 新的tag技术 1.1. Tag Files vs 原生写 SimpleTag 比较麻烦的 JSP 1.x 允许 Web 开发人员创建 Java 组件(称为标记处 ...
- fir.im Weekly - 94 个 iOS 开发资源推荐
距离 2016 年还有 17 个日夜,而你和回家只隔了一张 12306 验证码的距离,祝大家抢票顺利.本期 fir.im Weekly 收集了一些优秀的 GitHub 源码.开发工具和动画特效,希望对 ...
- 基于Rest服务实现的RPC
前言:现在RPC成熟的框架已经很多了,比喻Motan和Dubbo,但是今天我这里提供一种基于Rest服务的Rpc.和上一篇连着的http://www.cnblogs.com/LipeiNet/p/58 ...
- SQLSERVER中的ALLOCATION SCAN和RANGE SCAN
SQLSERVER中的ALLOCATION SCAN和RANGE SCAN 写这篇文章的开始,我还不知道ALLOCATION SCAN的工作原理是怎样的,网上资料少得可怜 求助了园子里的某位大侠,他看 ...
- 分享一个 C# Winfrom 下的 OutlookBar 控件的使用
最近在上网的时候,发现了这个C# 下的 OutlookBar 控件,看了一下感觉还真不错,特此记录一下. using System; using System.Drawing; using Syste ...
- 深入理解javascript作用域系列第二篇——词法作用域和动态作用域
× 目录 [1]词法 [2]动态 前面的话 大多数时候,我们对作用域产生混乱的主要原因是分不清楚应该按照函数位置的嵌套顺序,还是按照函数的调用顺序进行变量查找.再加上this机制的干扰,使得变量查找极 ...
- (转)sql的join图解
假设我们有两张表,Table A是左边的表,Table B是右边的表. 其各有四条记录,其中有两条记录是相同的,如下所示: 1 id name id name 2 -- ---- ...
- 安装android studio报错Failed to install Intel HAXM.
在安装android studio的过程中,安装到android的模拟器加速器(intel HAXM)这一步时,报错: HAXM是用来管理硬件加速的,估计是用了这个东西模拟器就能告别Eclipse的龟 ...