工作流Activiti异常积累

上一篇:Spring学习之整合Activiti(三)之Id生成

1、部署时生成流程图异常:Could not load image for process diagram creation: Can't create cache file

Activiti在Linux系统上部署流程时报以下错误:

[org.activiti.image.impl.DefaultProcessDiagramCanvas.initialize(DefaultProcessDiagramCanvas.java:245)]
Could not load image for process diagram creation: Can't create cache file!
 [WARN ][2019/01/09 18:06:06346][org.activiti.engine.impl.bpmn.deployer.BpmnDeployer.deploy(BpmnDeployer.java:160)]
Error while generating process diagram, image will not be stored in repository
 java.lang.NullPointerException
    at org.activiti.image.impl.DefaultProcessDiagramCanvas.drawTask(DefaultProcessDiagramCanvas.java:663)
    at org.activiti.image.impl.DefaultProcessDiagramCanvas.drawUserTask(DefaultProcessDiagramCanvas.java:826)
    at org.activiti.image.impl.DefaultProcessDiagramGenerator$6.draw(DefaultProcessDiagramGenerator.java:185)
    at org.activiti.image.impl.DefaultProcessDiagramGenerator.drawActivity(DefaultProcessDiagramGenerator.java:587)
    at org.activiti.image.impl.DefaultProcessDiagramGenerator.generateProcessDiagram(DefaultProcessDiagramGenerator.java:494)
    at org.activiti.image.impl.DefaultProcessDiagramGenerator.generateDiagram(DefaultProcessDiagramGenerator.java:403)
    at org.activiti.image.impl.DefaultProcessDiagramGenerator.generateDiagram(DefaultProcessDiagramGenerator.java:425)
    at org.activiti.engine.impl.bpmn.deployer.BpmnDeployer.deploy(BpmnDeployer.java:155)
    at org.activiti.engine.impl.persistence.deploy.DeploymentManager.deploy(DeploymentManager.java:58)
    at org.activiti.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:106)
    at org.activiti.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:37)
    at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
    at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
    at org.activiti.engine.impl.RepositoryServiceImpl.deploy(RepositoryServiceImpl.java:79)
    at org.activiti.engine.impl.repository.DeploymentBuilderImpl.deploy(DeploymentBuilderImpl.java:156)
    at net.northking.service.impl.activiti.ModelServiceImpl.deploy(ModelServiceImpl.java:76)
    at net.northking.controller.activiti.ModelController.deployByModelId(ModelController.java:171)
    at net.northking.controller.activiti.ModelController.deploy(ModelController.java:108)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    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:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    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:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:748)

并且生成流程图失败,从报错信息可以看到是DefaultProcessDiagramCanvas.java的663行导致,进去后(位于activiti-image-generator-5.22.0.jar包的org.activiti.image.impl下)发现这是这行报空指针:

method_drawTask.png

从这里不难猜测是icon为空,再查找该方法的引用处:drawUserTask方法:

method_drawUserTask.png

再看USERTASK_IMAGE的赋值的地方:

method_initialize.png

可以看到正是这里抛出的异常,错误信息是 Can't create cache file!查看ImageIO源代码发现其中使用了一个缓冲区,在使用ImageIO进行图片读写操作时,Linux默认会使用缓存目录:${tomcat}/temp,在此缓存目录会生成缓存文件imageio4138671232726624650.tmp(这一串数字应该是当前时间戳,临时文件名),有些生产或测试环境的tomcat,会将temp目录删除,因此报错Can't create cache file! 其实已经说得很明显,缓冲区文件无法创建,找到缓冲区目录看一下即可找到原因,目录不存在、目录不可写等等。

4种解决方法如下

  1. 在tomcat下新建temp目录;

  2. 与方法1相似,通过ImageIO.setCacheDirectory(cacheDirectory);设置任意的、存在的缓存目录

  3. ImageIO默认是使用缓存目录,可以通过ImageIO.setUseCache(false)来设置,更改缓存策略,不使用文件目录缓存,使用内存缓存

  4. 不使用ImageIO,换成其它JDK方法
    ImageIO.write(bi, "jpg", baos);
    换成:
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(response.getOutputStream());
    encoder.encode(image);

解决方案摘自:https://blog.csdn.net/cwfreebird/article/details/51820993

2、ActivitiWrongDbException: version mismatch: activiti library version is '5.22.0.0', db version is null Hint

Activiti配置时,导入数据表的创建sql文件后,启动项目,报以下错误:

Caused by: org.activiti.engine.ActivitiWrongDbException: version mismatch: activiti library version is '5.22.0.0', db version is null Hint: Set <property name="databaseSchemaUpdate" to value="true" or value="create-drop" (use create-drop for testing only!) in bean processEngineConfiguration in activiti.cfg.xml for automatic schema creation
    at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCheckVersion(DbSqlSession.java:920)
    at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1419)
    at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:27)
    at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
    at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
    at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:80)
    at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:613)
    at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:65)
    at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:60)
    at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
    ... 41 more

这个是由于数据库内的版本跟实际的版本不匹配导致的(ACT_GE_PROPERTY表),我这是由于导数据的时候该表数据部分未导入成功,导致一直报改错误,我的pom.xml中的activiti 版本为 5.22.0.0,而是数据表ACT_GE_PROPERTY中为null:

image.png

该表插入以下数据即可。

INSERT INTO `act_ge_property` VALUES ('next.dbid', '1', 1);
INSERT INTO `act_ge_property` VALUES ('schema.history', 'create(5.22.0.0)', '1');
INSERT INTO `act_ge_property` VALUES ('schema.version', '5.22.0.0', '1');

其中的5.22.00与pom.xml中的activiti的版本保持一致。
sql表数据如下:

image.png

3、no resource found with name '需求提交流程模型.requirementConfirmProcess.png' in deployment '180001'

现象:点击流程图,图片加载失败,后台日志为:

 org.activiti.engine.ActivitiObjectNotFoundException: no resource found with name '需求提交流程模型.requirementConfirmProcess.png' in deployment '180001'
    at org.activiti.engine.impl.cmd.GetDeploymentResourceCmd.execute(GetDeploymentResourceCmd.java:58)
    at org.activiti.engine.impl.cmd.GetDeploymentResourceCmd.execute(GetDeploymentResourceCmd.java:30)
    at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
    at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
    at org.activiti.engine.impl.RepositoryServiceImpl.getResourceAsStream(RepositoryServiceImpl.java:113)
    at net.northking.activiti.service.ProcessService.getDiagramByProDefinitionId_noTrace(ProcessService.java:435)
    at net.northking.activiti.controller.ProcessController.loadByDeployment(ProcessController.java:749)
    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)

调用方法 net.northking.activiti.service.ProcessService.javagetDiagramByProDefinitionId_noTrace方法:

public InputStream getDiagramByProDefinitionId_noTrace(String resourceType, String deploymentId) throws Exception {
        ProcessDefinition processDefinition = findProcessDefinitionByDeploymentId(deploymentId);
        String resourceName = "";
        if (resourceType.equals("png") || resourceType.equals("image")) {
            resourceName = processDefinition.getDiagramResourceName();
        } else if (resourceType.equals("xml")) {
            resourceName = processDefinition.getResourceName();
        }
        InputStream resourceAsStream = null;
        if (StringUtil.isNotEmpty(resourceName)) {
            resourceAsStream = repositoryService.getResourceAsStream(deploymentId, resourceName);
        }
        return resourceAsStream;
    }

继续往下走,org.activiti.engine.impl.RepositoryServiceImpl.java

  public InputStream getResourceAsStream(String deploymentId, String resourceName) {
    return commandExecutor.execute(new GetDeploymentResourceCmd(deploymentId, resourceName));
  }
  

最后在org.activiti.engine.impl.cmd.GetDeploymentResourceCmd.java的execute方法抛出异常:

  public InputStream execute(CommandContext commandContext) {
    if (deploymentId == null) {
      throw new ActivitiIllegalArgumentException("deploymentId is null");
    }
    if(resourceName == null) {
      throw new ActivitiIllegalArgumentException("resourceName is null");
    }
    
    ResourceEntity resource = commandContext
      .getResourceEntityManager()
      .findResourceByDeploymentIdAndResourceName(deploymentId, resourceName);
    if(resource == null) {
      if(commandContext.getDeploymentEntityManager().findDeploymentById(deploymentId) == null) {
        throw new ActivitiObjectNotFoundException("deployment does not exist: " + deploymentId, Deployment.class);
      }
      else
      {
        throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName + "' in deployment '" + deploymentId + "'", InputStream.class);
      }
    }
    return new ByteArrayInputStream(resource.getBytes());
  }

场景重现并分析:(可以在这时,即先启动服务,再执行init流程模型相关sql文件)在数据库已有流程且未部署,且act_ge_property表中的next.dbid为180001;如下图:

image.png

(也可以在这时,启动服务,再部署流程,如果前一个步骤执行完毕没有操作过流程则不用在此处重启服务)部署(任何)一个流程,此时该流程的部署id一定为180001(不清楚原因的话可以详看 上一篇:Spring学习之整合Activiti(三)之Id生成 ),并会往act_ge_bytearray表插入两条180002、180003的数据:

image.png

然后执行一个新增流程的sql文件:

image.png

执行完成后数据表如下:

image.png

可以看到act_ge_bytearray中,新增流程模型的180002、180003覆盖了之前部署的流程的180002、180003信息,所以导致获取act_ge_bytearray之前的180002、180003流程信息为null,故抛错

4、deployment '180001' didn't put process definition 'requirementConfirmProcess:1:180004' in the cache

现象:启动流程或获取流程追踪图失败,后台日志为:

Caused by: org.activiti.engine.ActivitiException: deployment '180001' didn't put process definition 'requirementConfirmProcess:1:180004' in the cache
    at org.activiti.engine.impl.persistence.deploy.DeploymentManager.resolveProcessDefinition(DeploymentManager.java:189)
    at org.activiti.engine.impl.persistence.deploy.DeploymentManager.findDeployedProcessDefinitionById(DeploymentManager.java:77)
    at org.activiti.engine.impl.cmd.GetDeploymentProcessDefinitionCmd.execute(GetDeploymentProcessDefinitionCmd.java:39)
    at org.activiti.engine.impl.cmd.GetDeploymentProcessDefinitionCmd.execute(GetDeploymentProcessDefinitionCmd.java:26)
    at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
    at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
    at org.activiti.engine.impl.RepositoryServiceImpl.getDeployedProcessDefinition(RepositoryServiceImpl.java:139)
    at net.northking.activiti.util.ProcessDefinitionCache.getProcessDefination(ProcessDefinitionCache.java:81)
    at net.northking.activiti.service.ProcessService.getActivitiProccessImage(ProcessService.java:464)
    ... 42 more

启动流程和获取流程追踪图都是在net.northking.activiti.util.ProcessDefinitionCache.java的getProcessDefination方法抛错,该方法代码为:

    public ProcessDefinition getProcessDefination(String processDefinitionId) {
        ProcessDefinition processDefinition = map.get(processDefinitionId);

        if (processDefinition == null) {
            if (null == repositoryService) {
                repositoryService = ApplicationContextHandler.getBean(RepositoryService.class);
            }
            processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
                    .getDeployedProcessDefinition(processDefinitionId);
            if (processDefinition != null) {
                put(processDefinitionId, processDefinition);
            }
        }
        return processDefinition;
    }

跟踪代码,可以看到,抛错的地方为:
org.activiti.engine.impl.persistence.deploy.DeploymentManager.java中的resolveProcessDefinition方法:

  public ProcessDefinitionEntity resolveProcessDefinition(ProcessDefinitionEntity processDefinition) {
    String processDefinitionId = processDefinition.getId();
    String deploymentId = processDefinition.getDeploymentId();
    processDefinition = processDefinitionCache.get(processDefinitionId);
    if (processDefinition==null) {
      DeploymentEntity deployment = Context
        .getCommandContext()
        .getDeploymentEntityManager()
        .findDeploymentById(deploymentId);
      deployment.setNew(false);
      deploy(deployment, null);
      processDefinition = processDefinitionCache.get(processDefinitionId);
      
      if (processDefinition==null) {
        throw new ActivitiException("deployment '"+deploymentId+"' didn't put process definition '"+processDefinitionId+"' in the cache");
      }
    }
    return processDefinition;
  }
  

场景重现及分析:
场景类似问题3
1、部署已有流程,
2、然后运行新增流程模型的sql文件,
3、重启服务(或者先重启再运行新增流程模型的sql文件);
4、启动已部署的流程,报:

 org.activiti.engine.ActivitiException: deployment '180001' didn't put process definition 'requirementConfirmProcess:1:180004' in the cache
    at org.activiti.engine.impl.persistence.deploy.DeploymentManager.resolveProcessDefinition(DeploymentManager.java:189)
    at org.activiti.engine.impl.persistence.deploy.DeploymentManager.findDeployedProcessDefinitionById(DeploymentManager.java:77)
    at org.activiti.engine.impl.cmd.GetDeploymentProcessDefinitionCmd.execute(GetDeploymentProcessDefinitionCmd.java:39)
    at org.activiti.engine.impl.cmd.GetDeploymentProcessDefinitionCmd.execute(GetDeploymentProcessDefinitionCmd.java:26)
    at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
    at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:37)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
    at org.activiti.engine.impl.RepositoryServiceImpl.getDeployedProcessDefinition(RepositoryServiceImpl.java:139)
    at net.northking.activiti.util.ProcessDefinitionCache.getProcessDefination(ProcessDefinitionCache.java:81)
    at net.northking.activiti.util.ProcessDefinitionCache.getActivities(ProcessDefinitionCache.java:108)
    at net.northking.activiti.service.CusUserTaskService.initSingleActivitiInfo(CusUserTaskService.java:79)
    at net.northking.activiti.service.CusUserTaskService.initProcessUserTaskInfo(CusUserTaskService.java:64)
    at net.northking.activiti.controller.ProcessController.initUserTaskAssignees(ProcessController.java:415)
    at net.northking.activiti.controller.ProcessController.startProcess(ProcessController.java:376)
    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)

解决方案
目前的解决方法是:
1、在每插入一条新的流程模型时,先判断其字段EDITOR_SOURCE_VALUE_ID_(即为act_ge_bytearray中的ID_ 值)和EDITOR_SOURCE_EXTRA_VALUE_ID_(即为act_ge_bytearray中的ID_ 值) 在表 act_ge_bytearray中是否存在(因为不能直接更新外键,所以该操作需要去除外键),
存在的条件是ID_NAME_都相等:
如果只有ID_相等的话,则ID_的值+3000(这个值是我估算的),代码如下:


/* 当数据表act_ge_bytearray中已有主键但`NAME_` != 'source-extra'时,修改待插入数据的`ID_`为value(`ID_`)+3000*/

INSERT INTO `act_re_model` VALUES
('180001', '5', '项目变更流程模型', '180001', null, '2019-05-17 12:16:30.980', '2019-05-27 16:43:06.448', '1','{\"name\":\"项目变更流程模型\",\"revision\":1,\"description\":\"项目变更流程:\\n申请人发起变更,科技项目经理进行确认,确认不通过则退回至发起人,通过后流向pmo初审;\\npmo审批:驳回则退回到项目经理确认节点,通过则再判断条件:非重大项目 and 非重大变更 and 变更类型 等于 计划变更都成立时,归档并结束流程;条件不成立则启动oa系统中的流程,挂起当前流程,待oa系统的流程通过后回到当前流程,激活流程,判断是否为需求变更,不是的话直接归档当前流程;是需求变更的话,进行需求分析,分析驳回后退回到pmo初审,分析通过后进行需求分析确认节点,确认通过后流程归档。\"}', null, 
        (SELECT (case when (EXISTS (SELECT `ID_` FROM `act_ge_bytearray`  WHERE `ID_`='180002' AND `NAME_` != 'source'))
                    then '183002'
                    else '180002' 
                end) 
        FROM `act_ge_bytearray` limit 1),
        (SELECT (case when (EXISTS (SELECT `ID_` FROM `act_ge_bytearray`  WHERE `ID_`='180003' AND `NAME_` != 'source-extra'))
                    then '183003'
                    else '180003' 
                end) 
        FROM `act_ge_bytearray` limit 1),
        '')
ON DUPLICATE KEY UPDATE `REV_`=VALUES(`REV_`),`NAME_`=VALUES(`NAME_`),`KEY_`=VALUES(`KEY_`),`CATEGORY_`=VALUES(`CATEGORY_`),`CREATE_TIME_`=VALUES(`CREATE_TIME_`),`LAST_UPDATE_TIME_`=VALUES(`LAST_UPDATE_TIME_`),`VERSION_`=VALUES(`VERSION_`),`META_INFO_`=VALUES(`META_INFO_`),`DEPLOYMENT_ID_`=VALUES(`DEPLOYMENT_ID_`),`EDITOR_SOURCE_VALUE_ID_`=VALUES(`EDITOR_SOURCE_VALUE_ID_`),`EDITOR_SOURCE_EXTRA_VALUE_ID_`=VALUES(`EDITOR_SOURCE_EXTRA_VALUE_ID_`),`TENANT_ID_`=VALUES(`TENANT_ID_`);

2、删除act_ge_bytearray已有数据

DELETE FROM `act_ge_bytearray` WHERE `ID_`='180002' AND `NAME_` = 'source';
DELETE FROM `act_ge_bytearray` WHERE `ID_`='180003' AND `NAME_` = 'source-extra';

3、插入新数据,ID_act_re_model表的EDITOR_SOURCE_VALUE_ID_值和EDITOR_SOURCE_EXTRA_VALUE_ID_

image.png

去除外键的sql为:

ALTER TABLE `act_re_model`
DROP foreign key `ACT_FK_MODEL_SOURCE`;
ALTER TABLE `act_re_model`
DROP foreign key `ACT_FK_MODEL_SOURCE_EXTRA`;
ALTER TABLE `act_re_model`
DROP index `ACT_FK_MODEL_SOURCE`;
ALTER TABLE `act_re_model`
DROP index `ACT_FK_MODEL_SOURCE_EXTRA`;

上一篇:Spring学习之整合Activiti(三)之Id生成

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,684评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,143评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,214评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,788评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,796评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,665评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,027评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,679评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,346评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,664评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,766评论 1 331
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,412评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,015评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,974评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,073评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,501评论 2 343

推荐阅读更多精彩内容