错误如下:
2017-3-29
15:17:52~ERROR~org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:253)~Servlet.service() for servlet action threw exception
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.tcc.operator.dto.TblTcclinkClosure#1002]
at org.hibernate.engine.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:556)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:258)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:216)
at org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireUpdate(SessionImpl.java:559)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:547)
at org.hibernate.impl.SessionImpl.update(SessionImpl.java:539)
at com.tcc.operator.biz.OperatorBiz.updateLinkclosure(OperatorBiz.java:520)
at com.tcc.operator.action.UpdateConstructionAction.execute(UpdateConstructionAction.java:38)

一开始session.update(Object o)出现这样的问题,但是通过使用session.merge(Object o)解决了,因为merge()会判断session pool中是否有同样的对象,有则update(),没有则seve()。
但后来发现session.delete(Object o)也出现同样的问题。没办法,只能找根本原因。最后发现啊extends Action的时候我new了一个需要更新的Object,然后用ActionForm里的值赋值。这样一来,提供给hibernate更新的对象和你本来想要更新的对象属于不同对象,但却有相同的标识。因此hibernate抛出NonUniqueObjectException。
解决方法是,通过ActionForm里的标识,find真正要更新的对象,然后用ActionForm里的值替换该对象的值。
再执行update()或delete();问题就解决了。

org.hibernate.NonUniqueObjectException的更多相关文章

  1. org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread---------程序报错

    今天遇到了这个问题: org.hibernate.NonUniqueObjectException: a different object with the same identifier value ...

  2. hibernate异常:org.hibernate.NonUniqueObjectException

    异常:org.hibernate.NonUniqueObjectException 提示:a different object with the same identifier value was a ...

  3. opensessioninviewFilter导致org.hibernate.NonUniqueObjectException

    起因: 公司业务需求,增加了一个新的数据源,增加之后,起初一切正常,但是发现后台管理系统所有Ajax请求获取信息没有问题,但是涉及到保存操作就抛出异常. 异常: org.hibernate.NonUn ...

  4. Exception 06 : org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session :

    异常名称: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was ...

  5. org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

    保存实体异常 https://blog.csdn.net/zzzz3621/article/details/9776539 org.hibernate.NonUniqueObjectException ...

  6. org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session异常解决办法

    org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread ...

  7. 解决org.hibernate.NonUniqueObjectException的问题

    不知道是不是之前处理懒加载的问题对session工厂进行了处理,导致了之前没有问题的地方出现了错误. 当修改班级操作时出现了错误 前端错误信息 后台处理以及报错信息 16:37:36,034 ERRO ...

  8. org.hibernate.NonUniqueObjectException 原因及解决办法

    问题 使用hibernate更新对象时,出现如下错误: org.hibernate.NonUniqueObjectException: a different object with the same ...

  9. org.hibernate.NonUniqueObjectException:a different object with the same identifier value was alread

    转自: http://blog.csdn.net/zzzz3621/article/details/9776539 看异常提示意思已经很明显了,是说主键不唯一,在事务的最后执行SQL时,session ...

随机推荐

  1. [机器学习]回归--Decision Tree Regression

    CART决策树又称分类回归树,当数据集的因变量为连续性数值时,该树算法就是一个回归树,可以用叶节点观察的均值作为预测值:当数据集的因变量为离散型数值时,该树算法就是一个分类树,可以很好的解决分类问题. ...

  2. virualbox 虚拟机管理

    虚拟机调换后提示UUID一致,需要重新生成新的虚拟机文件的UUID,使用如下命令: D:\Program Files\Oracle\VirtualBox>VBoxManage internalc ...

  3. #1 Python灵活技巧

    前言 Python基础系列博文已顺利结束,从这一篇开始将进入探索更加高级的Python用法,Python进阶系列文章将包含面向对象.网络编程.GUI编程.线程和进程.连接数据库等.不过在进阶之前,先来 ...

  4. 翻译wiki(一):Bios boot partition

    文章翻译自wiki,水平有限,若有错万请见谅.原文:https://en.wikipedia.org/wiki/BIOS_boot_partition BIOS boot partition是一个分区 ...

  5. 反爬虫——使用chrome headless时一些需要注意的细节

    以前我们介绍过chrome headless的用法(https://www.cnblogs.com/apocelipes/p/9264673.html). 今天我们要稍微提一下其中一个细节. 反爬和w ...

  6. 如何快速将一个list<a>集合中的部分字段值组合成新的的list<b>部分*

    有的时候,我们只需要从老数据中拿一部分数据作为新的绑定数据,比如说绑定下拉框的时候需要构造我们需要的数据格式可以采用以下的方法 public class SelectDataViewModel { p ...

  7. 29.QT-自定义窗口拖动、自定义QToolButton/QPushButton开关按钮、界面阴影,声音等总结

    自定义窗口及拖动 1.自定义无边框窗口时,需要将窗口标志设为: Qt::FramelessWindowHint |Qt::WindowSystemMenuHint | Qt::WindowMinMax ...

  8. FastDFS搭建

    a.上传安装时需要的文件 ①:FastDFS_v5.05.tar.gz ②:fastdfs-nginx-module_v1.16.tar.gz ③:libfastcommon-1.0.7.tar.gz ...

  9. [转] 快速部署Tomcat项目的Shell脚本

    为了做集群测试,在每台机器上装了3个tomcat,每次发布项目的时候都要反复敲一些命令,重启tomcat之前先检查tomcat进程有没有停掉,没有还要手动kill该进程. 发布次数多了,操作就比较繁琐 ...

  10. 51单片机定时器实现LED闪烁

    要启用一个定时器,先要开启定时器,然后产生中断 系统中断: 初始化程序应完成如下工作: 对TMOD赋值,以确定T0和T1的工作方式. 计算初值,并将其写入TH0.TL0或TH1.TL1. 中断方式时, ...