【异常提示】

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. nwafu - java实习 JDBC练习 - 学生信息系统界面

    学生信息系统界面的实现 - JDBC writer:pprp 登录界面的实现: 分为两个部分: 1.LoginFrame.java : 用windowbuilder进行快速搭建界面,构建好登录的界面, ...

  2. 秒懂算法3——插入排序(C#实现)

    算法思路: 将n个元素分成[已排序]和[未排序]两部分.每次将[未排序]中的一个元素取出,插入到已排序中的相应位置.直至所有元素排序完毕. [已排序] [未排序] { { a[0] }         ...

  3. 在线前端 样式和js

    bootstrap+ jquery <link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstra ...

  4. zlib编译方法

    点击这里下载zlib1.2.8源码 http://www.zlib.net/fossils/ ##编译方法一## - 解压源码文件到指定目录,例如 x:\zlib - 打开VS2015的Develop ...

  5. cassandra 之 在spark-shell 中使用 spark cassandra connector 完整案例

    1.cassandra 准备 启动cqlsh, CQLSH_HOST=172.16.163.131 bin/cqlsh cqlsh>CREATE KEYSPACE productlogs WIT ...

  6. meta标签中的http-equiv属性使用介绍

      meta是html语言head区的一个辅助性标签.也许你认为这些代码可有可无.其实如果你能够用好meta标签,会给你带来意想不到的效果,meta 标签的作用有:搜索引擎优化(SEO),定义页面使用 ...

  7. chengdongyue的笔记

    ---------------------------------------- Linux 基础 --------------------------------1.Linux的诞生 1.unix两 ...

  8. jQuery 中$.ajax()方法参数详解

    $.ajax({ url:'test.do', data:{id:,name:'xiaoming'}, type:'post', dataType:'json', success:function(d ...

  9. Android6.0------权限申请管理(单个权限和多个权限申请)

    Android开发时,到6.0系统上之后,有的权限就得申请才能用了. Android将权限分为正常权限 和 危险权限 Android系统权限分为几个保护级别.需要了解的两个最重要保护级别是 正常权限  ...

  10. Python flask网站部署总结

    先开一贴,有空来总结下前段时间的网站部署情况.此次部署采用Gunicorn + Nginx + supervisor的组合在VPS环境中部署flask网站应用. Ubuntu环境准备 准备python ...