|
完整的错误报文:org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.kylink.component.entity.ScadaComponentGroupEntity#40283e816276154a01627615df650001] at org.hibernate.engine.internal.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:674)
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:119)
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:74)
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:859)
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:838)
at org.jeecgframework.core.common.dao.impl.GenericBaseCommonDao.delete(GenericBaseCommonDao.java:235)
at org.jeecgframework.core.common.service.impl.CommonServiceImpl.delete(CommonServiceImpl.java:68)
at com.kylink.component.service.impl.ScadaComponentTypeServiceImpl.doDelBus(ScadaComponentTypeServiceImpl.java:159)
at com.kylink.component.service.impl.ScadaComponentTypeServiceImpl.delete(ScadaComponentTypeServiceImpl.java:76)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy308.delete(Unknown Source)
at com.kylink.component.controller.ScadaComponentTypeController.doDel(ScadaComponentTypeController.java:183)
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.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.jeecgframework.core.aop.GZipFilter.doFilter(GZipFilter.java:93)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:140)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:150)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
源代码:
public void delete(ScadaComponentTypeEntity entity) throws Exception{
//执行删除操作增强业务
boolean isGroup = this.doDelBus(entity);
if(!isGroup)
super.delete(entity);
}
private boolean doDelBus(ScadaComponentTypeEntity t) throws Exception{ //-----------------sql增强 start----------------------------
//-----------------sql增强 end------------------------------
//-----------------java增强 start---------------------------
//-----------------java增强 end-----------------------------
List<ScadaComponentGroupEntity> groupList = loadAll(ScadaComponentGroupEntity.class);
List<ScadaComponentTypeEntity> allTypeList = loadAll(ScadaComponentTypeEntity.class);
objectList = loadAll(ScadaInstanceComponentEntity.class);
List<ScadaComponentTypeEntity> childTypeList = new ArrayList<ScadaComponentTypeEntity>();
//删除元件,首先判断是否被已存在的画面所引用
Boolean isGroup = false;
for (ScadaComponentGroupEntity group : groupList) {
// 说明删除的是组
if (t.getId().equals(group.getId())) {
for (ScadaComponentTypeEntity typeEntity : allTypeList) {
if (typeEntity.getCgroup().equals(t.getId())) {
if (componentHasUsered(typeEntity.getId()))
throw new RuntimeException("Delete Component Group False," + typeEntity.getCname() + "Is In Use");
childTypeList.add(typeEntity);
}
}
isGroup = true;
}
}
// 然后判断每个元件是否被现有画面所使用,如果已被使用,则不能删除
if (isGroup) {
if (childTypeList.size() > 0) {
deleteAllEntitie(childTypeList);
}
ScadaComponentGroupEntity group = new ScadaComponentGroupEntity();
group.setId(t.getId());
delete(group);
} else {
if (componentHasUsered(t.getId()))
throw new RuntimeException("Delete Component Group False," + t.getCname() + "Is In Use");
}
return isGroup;
}
应用场景:我有两张表,分别存放的组信息和子节点信息。业务逻辑是删除组时,同时删除其下的所有节点。报错的那行是:执行删除组时。网上看的解决方案全是要操作session,比如session.clean。但我这两个表的信息没有保存到session里呀,有没有知道原因的。
|
|