错误如下:
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. 进程间通信IPC-内存共享

    函数: (1)int shmget(key_t key, int size, int shmflg),开辟或使用一块共享内存. (2)void *shmat(int shmid, const void ...

  2. Perl的列表和数组

    列表和数组 列表 使用括号包围的元素,括号中的元素使用逗号隔开的是列表. 列表中的元素可以是字符串.数值.undef或它们的混合. 列表中的字符串元素需要使用引号包围. 空列表是括号中什么都没有的列表 ...

  3. Redis基础认识及常用命令使用(一)--技术流ken

    Redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有序集 ...

  4. 业务开发(二)—— Spring框架

    0x01.使用枚举类,在MyBatis中 到了mapper.xml文件那里,如Status要与1进行对比,而不是1所对应的枚举字符串. 0x02.分页 Dao获取到的记录数,在Controller层放 ...

  5. [转]Build An Image Manager With NativeScript, Node.js, And The Minio Object Storage Cloud

    本文转自:https://www.thepolyglotdeveloper.com/2017/04/build-image-manager-nativescript-node-js-minio-obj ...

  6. 第一册:lesson seventy seven。

    原文:terrible toothache. Good morning Mr.Croft. Good morning nurse. I want to see the dentist,please. ...

  7. Updatepanel 后端返回后,在 Updatepanel 内控件的前端 js 失效问题

    实际情况:点击下箭头弹出列表,点击列表上的隐藏按钮隐藏列表. 背景:模块没有使用Js或者Jquery的Ajax功能,而是使用Asp.Net的Ajax控件--UpdatePanel + ScriptMa ...

  8. eclipse下SpringMVC+Maven+Mybatis+MySQL项目搭建

    这篇文章主要讲解使用eclipse对Spirng+SpringMVC+Maven+Mybatis+MySQL项目搭建过程,包括里面步骤和里面的配置文件如何配置等等都会详细说明. 接下来马上进入项目搭建 ...

  9. Java自动内存管理机制学习(一):Java内存区域与内存溢出异常

    备注:本文引用自<深入理解Java虚拟机第二版> 2.1 运行时数据区域 Java虚拟机在执行Java程序的过程中把它所管理的内存划分为若干个不同的数据区域.这些区域都有各自的用途,以及创 ...

  10. kubernetes认证和serviceaccount

    Service Account 为 Pod 提供必要的身份认证.所有的 kubernetes 集群中账户分为两类,Kubernetes 管理的 serviceaccount(服务账户) 和 usera ...