Show Table of Contents
13.4. Configuration
The JBoss BPM Suite engine does not save runtime data persistently by default. This means you can use the engine completely without persistence if necessary. However, if needed, you can configure the engine to use persistence by configuring it to do so. This usually requires adding the necessary dependencies, configuring a datasource and creating the engine with persistence configured.
13.4.1. Adding Dependencies
To use persistence, you must ensure that the necessary dependencies are available in the classpath of your application. Persistence is based on the Java Persistence API (JPA) by default and can thus work with several persistence mechanisms. We are using Hibernate. If you are using the Eclipse IDE and the JBoss BPM Suite plug-in, you must ensure that the necessary JAR files are added to your JBoss BPM Suite runtime directory. However, if you are using the JBoss BPM Suite runtime that is configured by default when using the JBoss BPM Suite installer , you need not do anything.
To manually add the necessary dependencies to your project, you first need the
jbpm-persistence-jpa.jar file, as that contains code for saving the runtime state whenever necessary. Next, you need various other dependencies, depending on the persistence solution and database you are using. For the default combination with Hibernate as the JPA persistence provider and using an H2 in-memory database and Bitronix for JTA-based transaction management, you need the following list of additional dependencies is needed:
- jbpm-persistence-jpa (org.jbpm)
- drools-persistence-jpa (org.drools)
- persistence-api (javax.persistence)
- hibernate-entitymanager (org.hibernate)
- hibernate-annotations (org.hibernate)
- hibernate-commons-annotations (org.hibernate)
- hibernate-core (org.hibernate)
- commons-collections (commons-collections)
- dom4j (dom4j)
- jta (javax.transaction)
- btm (org.codehaus.btm)
- javassist (javassist)
- slf4j-api (org.slf4j)
- slf4j-jdk14 (org.slf4j)
- h2 (com.h2database)
13.4.2. Manually Configuring JBoss BPM Suite Engine to Use Persistence
You can use the
JPAKnowledgeService to create your knowledge session. This gives you full access to the underlying configurations. You can create a new knowledge session using JPAKnowledgeService based on a knowledge base, a knowledge session configuration (if necessary) and an environment. Ensure that the environment contains a reference to your Entity Manager Factory. For example:
// create the entity manager factory and register it in the environment EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" ); Environment env = KnowledgeBaseFactory.newEnvironment(); env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf ); // create a new knowledge session that uses JPA to store the runtime state StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env ); int sessionId = ksession.getId(); // invoke methods on your method here ksession.startProcess( "MyProcess" ); ksession.dispose();
Additionally, you can use the
JPAKnowledgeService to recreate a session based on a specific session id. Here is an example:
// recreate the session from database using the sessionId ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env );
Note that we only save the minimal state that is required to continue execution of the process instance at some later point. It does not contain information about already executed nodes if that information is no longer relevant. This also means that process instances that are completed or aborted are removed from the database. To search for history-related information, you must use the history log.
In order to use Hibernate and the H2 database, add a persistence configuration file
persistence.xml to your classpath to configure JPA (or your own preference) in the META-INF directory as shown below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistenc version="2.0" xsi:schemaLocation=
"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance>
<persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/jbpm-ds</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class>
<class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class>
<class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform"/>
</properties>
</persistence-unit>
</persistence>
Here, the
persistence.xml file refers to a data source called jdbc/jbpm-ds. If you run your application in an application server, these containers typically allow you to easily set up data sources using some configuration (For example, placing a datasource configuration file in the deploy directory). For details, refer your application server documentation.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.