尚学堂OA项目里jbpm的入门测试模块中,我已经做了创建数据库表、发布了第一个流程、创建了第一个公文,可是触使开始流程向下一步走的时候,总不起作用,查找当前的流程节点时却总是输出“开始”,查看了好几天也不知道什么错,这是我的代码:
我的流程定义文件:
<process-definition name="文档测试流程">
<start-state name="开始">
<transition name="提交张三审批" to="张三审批"></transition>
</start-state>
<task-node name="张三审批">
<task name="审批1">
<assignment actor-id="张三"></assignment>
</task>
<transition name="提交李四审批" to="李四审批"></transition>
</task-node>
<task-node name="李四审批">
<task name="审批2">
<assignment actor-id="李四"></assignment>
</task>
<transition name="提交王五审批" to="王五审批"></transition>
</task-node>
<task-node name="王五审批">
<task name="审批3">
<assignment actor-id="王五"></assignment>
</task>
<transition name="流程结束" to="结束"></transition>
</task-node>
<end-state name="结束"></end-state>
</process-definition>
我的hibernate.cfg.xml文件就是按照视频说的,更改数据库配置,映射自己的映射文件;
我创建数据库的代码:
JbpmConfiguration.getInstance().createSchema();
我的发布流程代码:
static JbpmConfiguration jbpmConfiguration = JbpmConfiguration
.getInstance();
ProcessDefinition processDefinition = ProcessDefinition.parseXmlResource("process.xml");
JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
try{
jbpmContext.deployProcessDefinition(processDefinition);
}
finally{
jbpmContext.close();
}
我的创建公文代码:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
try{
session.beginTransaction();
Document document = new Document();
document.setTitle("公文标题");
document.setContent("公文的内容");
document.setCreator("赵一");
session.save(document);
session.getTransaction().commit();
}catch (Exception e) {
session.getTransaction().rollback();
}finally{
session.close();
}
我的创建流程实例并与公文绑定:
JbpmContext context = jbpmConfiguration.createJbpmContext();
context.setSessionFactory(HibernateUtil.getSessionFactory());
ProcessDefinition definition = context.getGraphSession().findLatestProcessDefinition("文档测试流程");
ProcessInstance processInstance = new ProcessInstance(definition);
context.save(processInstance);
//加载公文
Document doc = (Document)context.getSession().load(Document.class, 1);
System.out.println("processInstance id is "+processInstance.getId());
//将流程实例绑定到公文
doc.setProcessIntanceId(processInstance.getId());
//将公文绑定到流程实例,ContextInstance相当于一个变量的容器
processInstance.getContextInstance().createVariable("document", doc.getId());
context.close();
我的提交公文并触发起始节点向下一步:
JbpmContext context = jbpmConfiguration.createJbpmContext();
context.setSession(HibernateUtil.getSession());
Document doc = (Document)context.getSession().load(Document.class, 1);
ProcessInstance processInstance = context.getProcessInstance(doc.getProcessIntanceId());
//触发流程走向下一步
processInstance.getRootToken().signal();
context.close();
查看当前节点:
context.setSession(HibernateUtil.getSession());
Document doc = (Document)context.getSession().load(Document.class, 1);
System.out.println("doc id is "+doc.getId());
ProcessInstance processInstance = context.getProcessInstance(doc.getId());
//获取当前节点的位置
System.err.println(processInstance.getRootToken().getNode().getName());
就是执行“提交并触发起始流程向下一步”的时候log4j输出:
16:10:57,953 [main] WARN StatefulPersistenceContext : Narrowing proxy to class org.jbpm.graph.node.TaskNode - this operation breaks ==