Activiti7.0進級学習(八):ActivityがPersistenceExceptionを投げ出した


背景

  • activitiがなぜPersistenceException
  • を投げ出したのかを記録する

    プロセス

  • 操作プロセス
  • activitiの承認プロセスのノードがノードであるか、またはノードに署名します.
  • 承認者2人は同時に同意操作(complete)
  • を行う.
  • この異常は必ず現れる.
  • エラーメッセージ
  • 2020-08-05 15:20:27.904 ERROR [http-nio-9011-exec-9] o.activiti.engine.impl.interceptor.CommandContext - Error while closing command context 
    org.apache.ibatis.exceptions.PersistenceException: 
    ### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`gangxin_test`.`ACT_RU_IDENTITYLINK`, CONSTRAINT `ACT_FK_IDL_PROCINST` FOREIGN KEY (`PROC_INST_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`)) 
    ### The error may involve org.activiti.engine.impl.persistence.entity.IdentityLinkEntityImpl.insertIdentityLink-Inline 
    ### The error occurred while setting parameters 
    ### SQL: insert into ACT_RU_IDENTITYLINK (ID_, REV_, TYPE_, USER_ID_, GROUP_ID_, TASK_ID_, PROC_INST_ID_, PROC_DEF_ID_)     values (?,             1,             ?,             ?,             ?,             ?,             ?,             ?) 
    ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`gangxin_test`.`ACT_RU_IDENTITYLINK`, CONSTRAINT `ACT_FK_IDL_PROCINST` FOREIGN KEY (`PROC_INST_ID_`) REFERENCES `ACT_RU_EXECUTION` (`ID_`)) 
    	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) 
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200) 
    	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185) 
    	at org.activiti.engine.impl.db.DbSqlSession.flushRegularInsert(DbSqlSession.java:649) 
    	at org.activiti.engine.impl.db.DbSqlSession.flushInsertEntities(DbSqlSession.java:544) 
    	at org.activiti.engine.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:527) 
    	at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:417) 
    	at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:197) 
    	at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:75) 
    	at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:72) 
    	at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47) 
    	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) 
    	at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45) 
    	at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:29) 
    	at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:44) 
    	at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:39) 
    	at org.activiti.engine.impl.TaskServiceImpl.setAssignee(TaskServiceImpl.java:130) 
    	at com.bdfint.gangxin.workflow.service.impl.ProcessTaskServiceImpl.setAssignee(ProcessTaskServiceImpl.java:63) 
    	at com.bdfint.gangxin.workflow.service.impl.ProcessTaskServiceImpl$$FastClassBySpringCGLIB$$7e4c4d61.invoke(<generated>) 
    	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) 
    	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747) 
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) 
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) 
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) 
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 
    	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) 
    	at com.bdfint.gangxin.workflow.service.impl.ProcessTaskServiceImpl$$EnhancerBySpringCGLIB$$feb2217d.setAssignee(<generated>) 
    	at com.bdfint.gangxin.workflow.service.impl.BusinessTaskServiceImpl.completeTask(BusinessTaskServiceImpl.java:230) 
    	at com.bdfint.gangxin.workflow.service.impl.BusinessTaskServiceImpl.completeTask(BusinessTaskServiceImpl.java:196) 
    	at com.bdfint.gangxin.workflow.service.impl.BusinessTaskServiceImpl$$FastClassBySpringCGLIB$$47fb33b0.invoke(<generated>) 
    	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) 
    	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747) 
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) 
    	at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89) 
    	at com.bdfint.cloud.common.aspect.DistributedLockAspect.doDistributedLock(DistributedLockAspect.java:54) 
    	at sun.reflect.GeneratedMethodAccessor1181.invoke(Unknown Source) 
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    	at java.lang.reflect.Method.invoke(Method.java:498) 
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) 
    	at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) 
    	at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) 
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:174) 
    	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) 
    	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) 
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 
    	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 
    	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 
    	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) 
    	at com.bdfint.gangxin.workflow.service.impl.BusinessTaskServiceImpl$$EnhancerBySpringCGLIB$$e7719764.completeTask(<generated>) 
    	at com.bdfint.gangxin.workflow.controller.TaskController.complete(TaskController.java:33) 
    	at sun.reflect.GeneratedMethodAccessor1568.invoke(Unknown Source) 
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    	at java.lang.reflect.Method.invoke(Method.java:498) 
    	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) 
    	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 
    	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877) 
    	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783) 
    	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) 
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:877) 
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) 
    	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) 
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:158) 
    	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.filterAndRecordMetrics(WebMvcMetricsFilter.java:126) 
    	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:111) 
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.springframework.boot.actuate.web.trace.servlet.HttpTraceFilter.doFilterInternal(HttpTraceFilter.java:84) 
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) 
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) 
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) 
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) 
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) 
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) 
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) 
    	at org.apache.catalina.core.StandardHostValve.invoke$original$lbtTjaGP(StandardHostValve.java:140) 
    	at org.apache.catalina.core.StandardHostValve.invoke$original$lbtTjaGP$accessor$putWgHJU(StandardHostValve.java) 
    	at org.apache.catalina.core.StandardHostValve$auxiliary$WU3RIKPh.call(Unknown Source) 
    	at org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstMethodsInter.intercept(InstMethodsInter.java:93) 
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java) 
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) 
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 
    	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) 
    	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 
    	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) 
    	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) 
    	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 
    	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    	at java.lang.Thread.run(Thread.java:748) 
    
  • エラー情報分析をどう見ているかというと、投げ出された異常は、M y SQL L i n t e g r i t y ConstraintViolationExceptionです.実は違います.activitiはjava-connectorから投げ出された異常をキャプチャし、エラーメッセージを印刷し、activiti自身がmybatisフレームワークを使用し、PersistenceException
  • を投げ出した.
  • 理由はactivitiのcompleteの作業過程を理解することです.completeのワークフロー
  • 次に、このノードが「はい」または「サイン」です.前の承認者の承認が完了すると、このtaskIdに関するタスクデータ情報が削除されるため、後続のスレッドがcomplete操作を行う場合、データベースが操作されるため、この外部キー制約の異常を必ず報告します.
  • ソリューションは、署名または署名のため、このノードだけが署名に成功し、後の人が署名時に異常を投げ出しても、ビジネスロジックは異常をキャプチャし、友好的にフロントエンドを提示すればよいので、自分のビジネスロジックは完全に合理的です.
  • 結論:ほとんどのフレームワークは、最下位層の異常をキャプチャし、独自の異常を放出する.実は私たちのビジネスロジックの面でもこのPersistenceExceptionをキャプチャして、ビジネスシステムに属する異常を投げ出せばいいのです.

  • 小結

  • activitiの最下位の作業手順を理解する.なぜエラーメッセージを投げ出すのですか?原理は何ですか.