1、流程部署后 act_re_deployment 表的 KEY_ 字段没有值
原代码:
//发布流程
String processName = modelData.getName() + ".bpmn20.xml";
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment()
.name(modelData.getName())
//.key(modelData.getKey()) // 如果没有设置key的值的话就会出现这个问题
.addString(processName, new String(bpmnBytes, "UTF-8"));
修改后的:
//发布流程
String processName = modelData.getName() + ".bpmn20.xml";
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment()
.name(modelData.getName())
.key(modelData.getKey()) // 如果没有设置key的值的话就会出现这个问题
.addString(processName, new String(bpmnBytes, "UTF-8"));
.key(modelData.getKey()) 这一行设置key的值使其不为空
2、流程部署后 act_re_procdef 表的 KEY_ 和 ID_ 字段有问题
act_re_procdef表:
| 字段 | 格式 |
|---|---|
| ID_ | process_key:revision:id |
| KEY_ | process_key |
process_key 对应 act_re_model 表的 KEY_ 字段

activiti1.png
原因是在绘制流程图的时候,没有在流程图里设置 process_key 并且和 act_re_model 表的 KEY_ 字段保持一致,流程部署的时候act_re_procdef表的process_key 是从 .bpmn20.xml 的文件流里获取的

activiti2.png
protected ProcessDefinitionEntity transformProcess(BpmnParse bpmnParse, Process process) {
ProcessDefinitionEntity currentProcessDefinition = Context.getCommandContext().getProcessDefinitionEntityManager().create();
bpmnParse.setCurrentProcessDefinition(currentProcessDefinition);
/*
* Mapping object model - bpmn xml: processDefinition.id -> generated by activiti engine processDefinition.key -> bpmn id (required) processDefinition.name -> bpmn name (optional)
*/
currentProcessDefinition.setKey(process.getId());
currentProcessDefinition.setName(process.getName());
currentProcessDefinition.setCategory(bpmnParse.getBpmnModel().getTargetNamespace());
currentProcessDefinition.setDescription(process.getDocumentation());
currentProcessDefinition.setDeploymentId(bpmnParse.getDeployment().getId());
if (bpmnParse.getDeployment().getEngineVersion() != null) {
...
..
/*
* Mapping object model - bpmn xml: processDefinition.id -> generated by activiti engine processDefinition.key -> bpmn id (required) processDefinition.name -> bpmn name (optional)
*/
作者也在这里用注释说明 processDefinition的key对应bpmn 里的id(应该是和process_key一致),processDefinition的name对应 bpmn的name(可选)