java 代码
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.chinafi.node_attach.NodeAttach#0-4082670]
- at org.hibernate.engine.PersistenceContext.checkUniqueness(PersistenceContext.java:586)
- at org.hibernate.event.def.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:72)
- at org.hibernate.impl.SessionImpl.delete(SessionImpl.java:579)
- at com.chinafi.hibernate.Manipulation.operation(Manipulation.java:39)
- at com.chinafi.hibernate.Manipulation.delete(Manipulation.java:73)
- at com.chinafi.node_attach.DeleteNodeAttach.deleteNodeAttach(DeleteNodeAttach.java:38)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
- at java.lang.reflect.Method.invoke(Unknown Source)
- at org.apache.struts.beanaction.ActionInvoker.invoke(ActionInvoker.java:16)
- at org.apache.struts.beanaction.DefaultActionInterceptor.intercept(DefaultActionInterceptor.java:5)
- at org.apache.struts.beanaction.BeanAction.execute(BeanAction.java:246)
- at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
- at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
- at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
- at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at com.chinafi.filter.GlobalFilter.doFilter(GlobalFilter.java:25)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
- at java.lang.Thread.run(Unknown Source)
解决办法:
hibernate2.17中使用insertOrUpdate()方法
hibernate3.0以上使用merge()来合并两个session中的同一对象 session.delete(session.merge(object));