processdefinition.xml
<?xml version="1.0" encoding="UTF-8"?><process-definition
  xmlns=""  name="test1">
   <start-state name="start">
      <transition name="" to="张三审批"></transition>
   </start-state>
   <task-node name="张三审批">
      <task name="张三审批">
       <assignment actor-id="张三"/>
      </task>
      <transition name="" to="李四审批"></transition>
   </task-node>
   <task-node name="李四审批">
      <task name="李四审批">
       <assignment actor-id="李四"/>
      </task>
      <transition name="" to="王五审批"></transition>
   </task-node>
   <task-node name="王五审批">
      <task name="王五审批">
       <assignment actor-id="王五"/>
      </task>
      <transition name="" to="end1"></transition>
   </task-node>
   <end-state name="end1"></end-state>
</process-definition>//创建表
public void test(){
JbpmConfiguration.getInstance().createSchema();
}//创建对象
static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance("jbpm.cfg.xml");

public void test()
{

JbpmContext context = jbpmConfiguration.createJbpmContext();

ProcessDefinition def = ProcessDefinition.parseXmlResource("test1/processdefinition.xml");


try {
context.deployProcessDefinition(def);
} catch (Exception e) {
e.printStackTrace();
context.setRollbackOnly();
}finally{context.close();}
}static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
//创建公文
public void test()
{
JbpmContext context = jbpmConfiguration.createJbpmContext(); try {
Document doc = new Document();
doc.setTitle("*****测试TEST: "+ new Random().nextInt(999));
context.getSession().save(doc);
ProcessDefinition def =null;
 GraphSession graphSession = context.getGraphSession();  
try {
graphSession.findLatestProcessDefinition("test1");
} catch (Exception e) {
System.out.println("没找到");
}

ProcessInstance instance = new ProcessInstance(def);
context.save(instance);
long a=instance.getId();
int id=(int)a;
doc.setProcessInstanceId(id);
instance.getContextInstance().setVariable("document", doc.getId());

} catch (Exception e) {
e.printStackTrace();
context.setRollbackOnly();
}finally{context.close();}

}创建表,创建流程实例正常,创建公文出现经下异常:
java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
at org.jbpm.db.GraphSession.findLatestProcessDefinition(GraphSession.java:153)
at com.accp.vo.CreateDocument.test(CreateDocument.java:28)
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)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
org.jbpm.JbpmException: can't create a process instance when processDefinition is null没找到 at org.jbpm.graph.exe.ProcessInstance.<init>(ProcessInstance.java:128)
at org.jbpm.graph.exe.ProcessInstance.<init>(ProcessInstance.java:92)
at com.accp.vo.CreateDocument.test(CreateDocument.java:33)
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)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
异常打印说明了,查找不到流程实例对象,请教?

解决方案 »

  1.   

    你在任务的参与者里面配了没...Handle...actor
      

  2.   

    static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
        //创建公文
        public void test()
        {
            JbpmContext context = jbpmConfiguration.createJbpmContext();        try {
                Document doc = new Document();
                doc.setTitle("*****测试TEST: "+ new Random().nextInt(999));
                context.getSession().save(doc);
                ProcessDefinition def =null;
                 GraphSession graphSession = context.getGraphSession();  
                try {
                    graphSession.findLatestProcessDefinition("test1");
                } catch (Exception e) {
                    System.out.println("没找到");
                }
            
                ProcessInstance instance = new ProcessInstance(def);
                context.save(instance);
                long a=instance.getId();
                int id=(int)a;
                doc.setProcessInstanceId(id);
                instance.getContextInstance().setVariable("document", doc.getId());
                
            } catch (Exception e) {
                e.printStackTrace();
                context.setRollbackOnly();
            }finally{context.close();}
            
        }初级错误,没有把找到的ProcessDefinition 赋值给def.理所当然会找不到流程定义.