public void startProcessAndCompleteFistTask() {
JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
Session session = jbpmContext.getSession();
User creator = (User) session.get(User.class, 1);
// 1, 部署流程定义
ProcessDefinition pd = ProcessDefinition.parseXmlResource("报销/processdefinition.xml");
jbpmContext.deployProcessDefinition(pd);
// 2, 启动流程
ProcessInstance pi = pd.createProcessInstance();
System.out.println("3333333333"+pi.getId());
// 创建表单
LeaveBizForm bizForm = new LeaveBizForm();
bizForm.setCreator(creator);
bizForm.setCreationTime(new Date());
bizForm.setProcessName("报销");
bizForm.setProcessInstanceId(pi.getId());
bizForm.setBizFormStatus(BizFormStatus.APPROVEING);
bizForm.setType("交通费");
bizForm.setMoney(100);
// 设置变量
pi.getContextInstance().setVariable("leaveBizForm", bizForm);
pi.getContextInstance().setVariable("proposerId", creator.getId());
pi.getContextInstance().setVariable("proposer", creator.getName());
("proposer"));
pi.signal();
// 完成第一个任务(提交申请)
TaskInstance ti = (TaskInstance) pi.getTaskMgmtInstance().getTaskInstances().iterator().next();
ti.start();
System.out.println("***"+ti.getName());//TaskInstance 显示为空
ti.end();
System.out.println("GGGGGGGGGGGGGGGGGGGGGGGGGGG");//这句代码执行了
jbpmContext.close();
}
结果报错:16:27:21,359 [main] ERROR DbPersistenceService : hibernate commit failed
org.hibernate.HibernateException: instance not of expected entity type: org.jbpm.context.exe.variableinstance.UnpersistableInstance is not a: org.jbpm.context.exe.VariableInstance
[b]问题补充:[/b]
<?xml version="1.0" encoding="GBK"?>
<start-state name="开始">
<transition to="提交申请"></transition>
</start-state>
部门经理
<task-node name="经理审批">
<task name="经理审批">
<assignment class="com.hr.oa.process.handler.AssignmentHandlerImpl">
<roleName>
经理
</roleName>
</assignment>
</task>
<transition to="结束"></transition>
</task-node>
<decision name="decision2">
<handler class="com.hr.oa.process.handler.Decision2HandlerImpl"></handler>
<transition to="经理审批" name="报销金额大于1000元"></transition>
<transition to="结束" name="报销金额小于等于1000元"></transition>
</decision>
<end-state name="结束"></end-state>
<event type="node-enter">
<action class="com.hr.oa.process.handler.SetBizFormStatusActionHandler"></action>
</event>
这个是我写的工作流文件