object references an unsaved transient instance【异常】
【异常提示】
TransientObjectException: 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
异常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【异常】的更多相关文章
- ManyToMany【项目随笔】关于异常object references an unsaved transient instance
在保存ManyToMany 时出现异常: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.Tran ...
- object references an unsaved transient instance - save the transient instance before flushing异常问题处理
一.异常:org.hibernate.TransientObjectException: object references an unsaved transient instance - save ...
- 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(参考资料: ...
- 三大框架常遇的错误:hibernate : object references an unsaved transient instance
hibernate : object references an unsaved transient instance 该错误是操作顺序的问题,比如: save或update顺序问题---比方学生表和 ...
- 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 ...
- 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
object references an unsaved transient instance save the transient instance before flushing 对象引用未保存的 ...
- hibernate 对象状态异常:object references an unsaved transient instance - save the transient instance before flushing
我的问题出在,删除的对象对应的表中有一个外键,关联着另外一个表,可是另外一个表中没有数据,所以报了这个错误. 参考http://www.cnblogs.com/onlywujun/archive/20 ...
随机推荐
- python 贪婪和非贪婪模式
这样的正则表达式: r'\*(.+)\*' 如果想要匹配*something*这样的一个串按道理说是没问题的 但是如果文本是*this* is *something* 那么我们的正则表达式就会采取贪 ...
- web.xml上下文初始化参数
1.在web.xml文件中配置上下文参数 <!--<context-param>标签声明上下文初始化参数, --> <!-- 上下文初始化的参数可以被应用程序用所有ser ...
- QtCreator的中如何使用第三方依赖库
> https://blog.csdn.net/e5Max/article/details/9840331 ```LIBS += -L/usr/local/lib -lmath ``` ``` ...
- JavaScript权威指南--类型、值和变量
本章要点图 数据类型:计算机程序的运行需要对值(value)比如数字3.14或者文本"hello world"进行操作,在编程语言中,能够表示并操作的值的类型叫做数据类型(type ...
- JAVA常用数据结构API
Quene
- python面试题包含基础和Linux操作以及数据库相关
今天面试了一家公司,感觉表现的不是很好,记录一下面试的试题. python基础部分 python 是一门什么样的语言面向对象的语言有那些,python的面向对象和Java面向对象的区别 Python是 ...
- Maven 环境搭建及相应的配置
在一般的Java Web项目开发中,特别是基于Struts + hibernate + spring的框架的时候,会有很多的jar包,一般都会在项目文件中有一个lib文件夹,下面放所有相关的jar包. ...
- compass框架的sprite雪碧图的用法简要
---恢复内容开始--- **简介** CSS SPRITE 即 CSS雪碧,即是将诸多图片合成一张图片,然后使用CSS 的background和background-position属性渲染. 这样 ...
- web运行异常解决
端口占用: 在dos下,输入 netstat -ano|findstr 8080 //说明:查看占用8080端口的进程 显示占用端口的进程 taskkill /pid 6856 /f ...
- iOS开发:MKMapView地图内存持续增加的释放解决办法
内存持续增加的释放解决办法 最近修改一个用到MKMapView的项目,内存一直占用过多,每次拖拽地图时还会增加占用,且一直无法释放. 经过两天的排查,最后锁定是创建的self.map对象在加载地图的时 ...