jbpm开发首要的就是要建立数据库,可以执行sql也可以通过代码实现
hibernate.cfg.xml配置如下:mysql
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
 <!-- jdbc connection properties -->
 <property name="hibernate.dialect">
  org.hibernate.dialect.MySQLDialect
 </property>
 <property name="hibernate.connection.driver_class">
  com.mysql.jdbc.Driver
 </property>
 <property name="hibernate.connection.url">
  jdbc:mysql://localhost:3306/jbpm
 </property>
 <property name="hibernate.connection.username">root</property>
 <property name="hibernate.connection.password">123456</property>
 
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
 <property name="hibernate.cache.provider_class">
  org.hibernate.cache.HashtableCacheProvider
 </property>
 <!-- other hibernate properties
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.format_sql">true</property>
  <property name="hibernate.use_sql_comments">true</property>
 -->
 <!-- ############################################ -->
 <!-- # mapping files with external dependencies # -->
 <!-- ############################################ -->
 <!-- following mapping file has a dependendy on   -->
 <!-- 'bsh-{version}.jar'.                         -->
 <!-- uncomment this if you don't have bsh on your -->
 <!-- classpath.  you won't be able to use the     -->
 <!-- script element in process definition files   -->
 <!--
 <property name="myeclipse.connection.profile">mysql</property>
 <property name="connection.url">jdbc:mysql://localhost:3306/jbpm</property>
 <property name="connection.username">root</property>
 <property name="connection.password">123456</property>
 <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
 <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
 -->
 <mapping resource="org/jbpm/graph/action/Script.hbm.xml" />
 <!-- following mapping files have a dependendy on  -->
 <!-- 'jbpm-identity-{version}.jar', mapping files  -->
 <!-- of the pluggable jbpm identity component.     -->
 <!-- comment out the following 3 lines if you don't-->
 <!-- want to use the default jBPM identity mgmgt   -->
 <!-- component                                     -->
 <mapping resource="org/jbpm/identity/User.hbm.xml" />
 <mapping resource="org/jbpm/identity/Group.hbm.xml" />
 <mapping resource="org/jbpm/identity/Membership.hbm.xml" />
 <!-- ###################### -->
 <!-- # jbpm mapping files # -->
 <!-- ###################### -->
 <!-- hql queries and type defs -->
 <mapping resource="org/jbpm/db/hibernate.queries.hbm.xml" />
 <!-- graph.def mapping files -->
 <mapping resource="org/jbpm/graph/def/ProcessDefinition.hbm.xml" />
 <mapping resource="org/jbpm/graph/def/Node.hbm.xml" />
 <mapping resource="org/jbpm/graph/def/Transition.hbm.xml" />
 <mapping resource="org/jbpm/graph/def/Event.hbm.xml" />
 <mapping resource="org/jbpm/graph/def/Action.hbm.xml" />
 <mapping resource="org/jbpm/graph/def/SuperState.hbm.xml" />
 <mapping resource="org/jbpm/graph/def/ExceptionHandler.hbm.xml" />
 <mapping resource="org/jbpm/instantiation/Delegation.hbm.xml" />
 <!-- graph.node mapping files -->
 <mapping resource="org/jbpm/graph/node/StartState.hbm.xml" />
 <mapping resource="org/jbpm/graph/node/EndState.hbm.xml" />
 <mapping resource="org/jbpm/graph/node/ProcessState.hbm.xml" />
 <mapping resource="org/jbpm/graph/node/Decision.hbm.xml" />
 <mapping resource="org/jbpm/graph/node/Fork.hbm.xml" />
 <mapping resource="org/jbpm/graph/node/Join.hbm.xml" />
 <mapping resource="org/jbpm/graph/node/State.hbm.xml" />
 <mapping resource="org/jbpm/graph/node/TaskNode.hbm.xml" />
 <!-- context.def mapping files -->
 <mapping resource="org/jbpm/context/def/ContextDefinition.hbm.xml" />
 <mapping resource="org/jbpm/context/def/VariableAccess.hbm.xml" />
 <!-- taskmgmt.def mapping files -->
 <mapping
  resource="org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/def/Swimlane.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/def/Task.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/def/TaskController.hbm.xml" />
 <!-- module.def mapping files -->
 <mapping resource="org/jbpm/module/def/ModuleDefinition.hbm.xml" />
 <!-- bytes mapping files -->
 <mapping resource="org/jbpm/bytes/ByteArray.hbm.xml" />
 <!-- file.def mapping files -->
 <mapping resource="org/jbpm/file/def/FileDefinition.hbm.xml" />
 <!-- scheduler.def mapping files -->
 <mapping
  resource="org/jbpm/scheduler/def/CreateTimerAction.hbm.xml" />
 <mapping
  resource="org/jbpm/scheduler/def/CancelTimerAction.hbm.xml" />
 <!-- graph.exe mapping files -->
 <mapping resource="org/jbpm/graph/exe/Comment.hbm.xml" />
 <mapping resource="org/jbpm/graph/exe/ProcessInstance.hbm.xml" />
 <mapping resource="org/jbpm/graph/exe/Token.hbm.xml" />
 <mapping resource="org/jbpm/graph/exe/RuntimeAction.hbm.xml" />
 <!-- module.exe mapping files -->
 <mapping resource="org/jbpm/module/exe/ModuleInstance.hbm.xml" />
 <!-- context.exe mapping files -->
 <mapping resource="org/jbpm/context/exe/ContextInstance.hbm.xml" />
 <mapping resource="org/jbpm/context/exe/TokenVariableMap.hbm.xml" />
 <mapping resource="org/jbpm/context/exe/VariableInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/NullInstance.hbm.xml" />
 <mapping
  resource="org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml" />
 <!-- msg.db mapping files -->
 <mapping resource="org/jbpm/msg/Message.hbm.xml" />
 <mapping resource="org/jbpm/msg/db/TextMessage.hbm.xml" />
 <mapping resource="org/jbpm/command/ExecuteActionCommand.hbm.xml" />
 <mapping resource="org/jbpm/command/ExecuteNodeCommand.hbm.xml" />
 <mapping resource="org/jbpm/command/SignalCommand.hbm.xml" />
 <mapping resource="org/jbpm/command/TaskInstanceEndCommand.hbm.xml" />
 <!-- taskmgmt.exe mapping files -->
 <mapping resource="org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/exe/PooledActor.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml" />
 <!-- scheduler.exe mapping files -->
 <mapping resource="org/jbpm/scheduler/exe/Timer.hbm.xml" />
 <!-- logging mapping files -->
 <mapping resource="org/jbpm/logging/log/ProcessLog.hbm.xml" />
 <mapping resource="org/jbpm/logging/log/MessageLog.hbm.xml" />
 <mapping resource="org/jbpm/logging/log/CompositeLog.hbm.xml" />
 <mapping resource="org/jbpm/graph/log/ActionLog.hbm.xml" />
 <mapping resource="org/jbpm/graph/log/NodeLog.hbm.xml" />
 <mapping
  resource="org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml" />
 <mapping resource="org/jbpm/graph/log/ProcessStateLog.hbm.xml" />
 <mapping resource="org/jbpm/graph/log/SignalLog.hbm.xml" />
 <mapping resource="org/jbpm/graph/log/TokenCreateLog.hbm.xml" />
 <mapping resource="org/jbpm/graph/log/TokenEndLog.hbm.xml" />
 <mapping resource="org/jbpm/graph/log/TransitionLog.hbm.xml" />
 <mapping resource="org/jbpm/context/log/VariableLog.hbm.xml" />
 <mapping resource="org/jbpm/context/log/VariableCreateLog.hbm.xml" />
 <mapping resource="org/jbpm/context/log/VariableDeleteLog.hbm.xml" />
 <mapping resource="org/jbpm/context/log/VariableUpdateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml" />
 <mapping
  resource="org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/log/TaskLog.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml" />
 <mapping resource="org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml" />
</session-factory>
</hibernate-configuration>
测试代码
package com.strongit.bpm.filter;
import java.util.List;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;
import junit.framework.TestCase;
public class HelloWorldDbTest extends TestCase {
 static JbpmConfiguration jbpmConfiguration = null;
   static {
     // An example configuration file such as this can be found in
     // 'src/config.files'.  Typically the configuration information is in the
     // resource file 'jbpm.cfg.xml', but here we pass in the configuration
     // information as an XML string.
    
     // First we create a JbpmConfiguration statically.  One JbpmConfiguration
     // can be used for all threads in the system, that is why we can safely
     // make it static.
     jbpmConfiguration = JbpmConfiguration.parseXmlString(
       "<jbpm-configuration>" +
      
       // A jbpm-context mechanism separates the jbpm core
       // engine from the services that jbpm uses from
       // the environment. 
      
       "  <jbpm-context>" +
       "    <service name='persistence' " +
       "             factory='org.jbpm.persistence.db.DbPersistenceServiceFactory' />" +
       "  </jbpm-context>" +
      
       // Also all the resource files that are used by jbpm are
       // referenced from the jbpm.cfg.xml
      
       "  <string name='resource.hibernate.cfg.xml' " +
       "          value='hibernate.cfg.xml' />" +
       "  <string name='resource.business.calendar' " +
       "          value='org/jbpm/calendar/jbpm.business.calendar.properties' />" +
       "  <string name='resource.default.modules' " +
       "          value='org/jbpm/graph/def/jbpm.default.modules.properties' />" +
       "  <string name='resource.converter' " +
       "          value='org/jbpm/db/hibernate/jbpm.converter.properties' />" +
       "  <string name='resource.action.types' " +
       "          value='org/jbpm/graph/action/action.types.xml' />" +
       "  <string name='resource.node.types' " +
       "          value='org/jbpm/graph/node/node.types.xml' />" +
       "  <string name='resource.varmapping' " +
       "          value='org/jbpm/context/exe/jbpm.varmapping.xml' />" +
       "</jbpm-configuration>"
     );
   }
  
   public void setUp() {
     jbpmConfiguration.createSchema();
   }
  
   public void tearDown() {
     jbpmConfiguration.dropSchema();
   }
   public void testSimplePersistence() {
     // Between the 3 method calls below, all data is passed via the
     // database.  Here, in this unit test, these 3 methods are executed
     // right after each other because we want to test a complete process
     // scenario.  But in reality, these methods represent different
     // requests to a server.
    
     // Since we start with a clean, empty in-memory database, we have to
     // deploy the process first.  In reality, this is done once by the
     // process developer.
     deployProcessDefinition();
     // Suppose we want to start a process instance (=process execution)
     // when a user submits a form in a web application...
     processInstanceIsCreatedWhenUserSubmitsWebappForm();
     // Then, later, upon the arrival of an asynchronous message the
     // execution must continue.
     theProcessInstanceContinuesWhenAnAsyncMessageIsReceived();
   }
   public void deployProcessDefinition() {
     // This test shows a process definition and one execution
     // of the process definition.  The process definition has
     // 3 nodes: an unnamed start-state, a state 's' and an
     // end-state named 'end'.
     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='hello world'>" +
       "  <start-state name='start'>" +
       "    <transition to='s' />" +
       "  </start-state>" +
       "  <state name='s'>" +
       "    <transition to='end' />" +
       "  </state>" +
       "  <end-state name='end' />" +
       "</process-definition>"
     );
     // Lookup the pojo persistence context-builder that is configured above
     JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     try {
       // Deploy the process definition in the database
       jbpmContext.deployProcessDefinition(processDefinition);
     } finally {
       // Tear down the pojo persistence context.
       // This includes flush the SQL for inserting the process definition 
       // to the database.
       jbpmContext.close();
     }
   }
   public void processInstanceIsCreatedWhenUserSubmitsWebappForm() {
     // The code in this method could be inside a struts-action
     // or a JSF managed bean.
     // Lookup the pojo persistence context-builder that is configured above
     JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     try {
       GraphSession graphSession = jbpmContext.getGraphSession();
      
       ProcessDefinition processDefinition =
           graphSession.findLatestProcessDefinition("hello world");
    
       // With the processDefinition that we retrieved from the database, we
       // can create an execution of the process definition just like in the
       // hello world example (which was without persistence).
       ProcessInstance processInstance =
           new ProcessInstance(processDefinition);
      
       Token token = processInstance.getRootToken();
       assertEquals("start", token.getNode().getName());
       // Let's start the process execution
       token.signal();
       // Now the process is in the state 's'.
       assertEquals("s", token.getNode().getName());
      
       // Now the processInstance is saved in the database.  So the
       // current state of the execution of the process is stored in the
       // database. 
       jbpmContext.save(processInstance);
       // The method below will get the process instance back out
       // of the database and resume execution by providing another
       // external signal.
     } finally {
       // Tear down the pojo persistence context.
       jbpmContext.close();
     }
   }
   public void theProcessInstanceContinuesWhenAnAsyncMessageIsReceived() {
     // The code in this method could be the content of a message driven bean.
     // Lookup the pojo persistence context-builder that is configured above
     JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
     try {
       GraphSession graphSession = jbpmContext.getGraphSession();
       // First, we need to get the process instance back out of the database.
       // There are several options to know what process instance we are dealing
       // with here.  The easiest in this simple test case is just to look for
       // the full list of process instances.  That should give us only one
       // result.  So let's look up the process definition.
      
       ProcessDefinition processDefinition =
           graphSession.findLatestProcessDefinition("hello world");
       // Now, we search for all process instances of this process definition.
       List processInstances =
           graphSession.findProcessInstances(processDefinition.getId());
      
       // Because we know that in the context of this unit test, there is
       // only one execution.  In real life, the processInstanceId can be
       // extracted from the content of the message that arrived or from
       // the user making a choice.
       ProcessInstance processInstance =
           (ProcessInstance) processInstances.get(0);
      
       // Now we can continue the execution.  Note that the processInstance
       // delegates signals to the main path of execution (=the root token).
       processInstance.signal();
       // After this signal, we know the process execution should have
       // arrived in the end-state.
       assertTrue(processInstance.hasEnded());
      
       // Now we can update the state of the execution in the database
       jbpmContext.save(processInstance);
     } finally {
       // Tear down the pojo persistence context.
       jbpmContext.close();
     }
   }

}