【异常提示】

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【异常】的更多相关文章

  1. ManyToMany【项目随笔】关于异常object references an unsaved transient instance

    在保存ManyToMany  时出现异常: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.Tran ...

  2. object references an unsaved transient instance - save the transient instance before flushing异常问题处理

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

  3. 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(参考资料: ...

  4. 三大框架常遇的错误:hibernate : object references an unsaved transient instance

    hibernate : object references an unsaved transient instance 该错误是操作顺序的问题,比如: save或update顺序问题---比方学生表和 ...

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

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

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

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

  8. object references an unsaved transient instance save the transient instance before flushing

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

  9. hibernate 对象状态异常:object references an unsaved transient instance - save the transient instance before flushing

    我的问题出在,删除的对象对应的表中有一个外键,关联着另外一个表,可是另外一个表中没有数据,所以报了这个错误. 参考http://www.cnblogs.com/onlywujun/archive/20 ...

随机推荐

  1. bzoj 1270: [BeijingWc2008]雷涛的小猫 简单dp+滚动数组

    1270: [BeijingWc2008]雷涛的小猫 Time Limit: 50 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Descrip ...

  2. 嵌入式 Web workers

    前言 虽然worker可以将复杂的运算放入单独线程去运算,不阻塞UI线程,但是,由于worker()的构造函数的参数不能读取本地的文件,只能来自网络,所以当在一个项目里想使用本地的模块函数,是一个很麻 ...

  3. [Vue]组件——插槽:slot(匿名插槽,具名插槽)与slot-scope(作用域插槽)

    1.单个插槽 | 匿名插槽 1.1<navigation-link> 子组件定义为: <a v-bind:href="url" class="nav-l ...

  4. 微信小程序------轮播图

    swiper 微信小程序实现轮播图,和网站,APP的效果差不多,代码少,效率高. 先来看看效果图: 主要用swiper + swiper-item来实现 <view class='swiper' ...

  5. Tomcat中session共享问题的简单解决办法

    tomcat-redis-session-manager 使用redis配置tomcat共享session 结构图: 分析: 分布式web server集群部署后需要实现session共享,针对 to ...

  6. DSP基础学习-ADC采样

    DSP基础学习-ADC采样 彭会锋 2015-04-27 22:30:03 在查看ADC采样例程的时候我发现了下面的代码挺有意思的 EALLOW; GpioCtrlRegs.GPAMUX2.bit.G ...

  7. Spring事务源码分析总结

    Spring事务是我们日常工作中经常使用的一项技术,Spring提供了编程.注解.aop切面三种方式供我们使用Spring事务,其中编程式事务因为对代码入侵较大所以不被推荐使用,注解和aop切面的方式 ...

  8. 转:在Eclipse的Debug页签中设置虚拟机参数

    http://blog.csdn.net/decorator2015/article/details/50914479 在Eclipse的Debug页签中设置虚拟机参数 步骤 1,Run->De ...

  9. 同一主机,不同域名绑定不同网站(IIS主机头实现方法)

    说明: 网站A域名:www.weba.com 网站A路径:D:\website\weba 网站B域名:www.webb.com 网站B路径:D:\website\webb 公用主机IP:111.222 ...

  10. 什么是Quartz?

    什么是Quartz Quartz是一个开源的作业调度框架,Quartz根据用户设定的时间规则来执行作业,使用场景:在平时的工作中,估计大多数都做过轮询调度的任务,比如定时轮询数据库同步,定时邮件通知. ...