今天在使用一对多,多对一保存数据的时候出现了这个错误

Hibernate错误:


Exception in thread "main" org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: zhongfucheng.domain.Employee

为啥出现这个错误呢???在保存对象的时候,发现这个对象还有存在外键,这个外键是在另一个实体里面。这个实体如果不存在或者实体的主键为空,就会报这个错误!

而我在保存的时候,并没有把拥有外键的对象保存进去….只保存了“一”方面的对象。

//创建对象Dept dept = new Dept();dept.setDeptName("开发部");Employee zs = new Employee();zs.setEmpName("张珊");zs.setSalary(1111);Employee ls = new Employee();ls.setEmpName("李四");ls.setSalary(2222);//添加关系dept.getSet().add(zs);dept.getSet().add(ls);session.save(dept);/*当时我没有把Emploey对象保存一起保存...因此出现了这个错误session.save(zs);session.save(ls);*/

还有一个解决方案:在映射文件中配置级联保存更新

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>

Exception in thread main org.hibernate.TransientObjectException: object references an unsaved tran相关推荐

  1. Hibernate中的级联策略和object references an unsaved transient instance - save the transient instance before

    本片博文整理关于Hibernate中级联策略cascade和它导致的异常: Exception in thread "main" org.hibernate.TransientOb ...

  2. object references an unsaved transient instance - save the transient instance before flushing

    刚开是在写项目的时候,去掉了很多jar包所以才会出现这个问题 Struts Problem Report Struts has detected an unhandled exception: Mes ...

  3. object references an unsaved transient instance - save the transient instance before flushing .

    http://blog.csdn.net/zdwzzu2006/article/details/7552234 异常1:not-null property references a null or t ...

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

    问题内容: 在一个hibernate项目中,为一个Model类添加一个多对一的配置 当表单中选择数据时对其多对一对象进行保存操作,没有选择的话则不对其做任何操作,如下面代码:当Attach不为空的情况 ...

  5. object references an unsaved transient instance - save the transient instance before flushing 解决过程。

    前言 本篇博客记录一个Spring JPA报错的解决方案.这个报错源自于一个需求的的改动,由于原始的接口执行过于缓慢,所以要改造成为异步通知模式,也因此遇到了这个报错,浪费了一上午时间. 情景还原 由 ...

  6. 解决object references an unsaved transient instance - save the transient instance before flushing 的错误

    异常信息: Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transie ...

  7. Exception in thread main java.lang.OutOfMemoryError: Java heap space

    在做大批量数据测试的时候,服务端初始化出现问题 测试规模,没个站2万点量测数据,整个数据超过20万,初始化过程中对量测数据初始化,按站分别初始化,但是初始化到总数据量10万的时候就会报内存溢出错误. ...

  8. hive启动报错:Exception in thread “main“ java.lang.NoSuchMethodError: com.google.common.base.Precondition

    报错如下 Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Precon ...

  9. Exception in thread “main“ java.lang.IllegalAccessException

    package com.fan.reflect;import com.fan.model.User; import java.lang.reflect.Field;public class 根据属性名 ...

最新文章

  1. Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
  2. CrossPHP框架的常用操作
  3. win10系统的服务器在哪里设置密码,window10怎么设置密码
  4. 集算器(仓库版)发布,黑科技获得用户好评
  5. 必须收藏!没有经验的程序员该怎么找工作?
  6. 实训项目:PHP双色球效果实现
  7. 二元分类(Binary Classfication)与logistic回归
  8. 决定了,儿童节我们用python画这个...
  9. Ae 效果快速参考:杂色和颗粒
  10. Android接入谷歌广告 - 发现各种坑
  11. linux parted 直接删除分区,CentOS7硬盘分区,删除分区,格式化分区硬盘,支持4T硬盘,fdisk,parted简单用法...
  12. Latex使用本地字体
  13. TeamViewer远程连接群辉
  14. magento|paypal快速结账和结账页开发疑难
  15. 采集规则七:河溪小说网 www.518cqdl.com 适用于-易读系统小说站河溪小说网的采集规则
  16. stft的窗函数设计要求和方法(COLA)
  17. html设置浏览器为ie9,Win10系统如何设置IE浏览器为IE9标准
  18. matlab机器人工具箱(1)
  19. 000929.CSI是China Securities Index中证指数
  20. 安卓系统主板链接USB声卡,卡号配置和授权说明

热门文章

  1. Django工程中,pycharm运行manage.py,提示8000端口占用问题error:That port is already in use
  2. Android开发过程中遇到的异常
  3. 基于小波分析的打鼾(阻塞性睡眠呼吸暂停)检测
  4. Docker官方教程
  5. 热评云厂商:品高云4.62亿元,发力行业云,掘金实属不易
  6. Ubuntu20.04安装nvidia显卡驱动并解决重启后黑屏问题
  7. html扫码支付,WEB端第三方支付接入 - 支付宝 - 扫码支付
  8. Matlab 自相关检测 :自相关函数xcorr
  9. 【ONE·C || 初识C语言 】
  10. html5使用websocket发送(PCM)音频数据到服务器,再转在wav文件