此内容没有您所选择的语言版本。
15.4. Persistence configuration
15.4.1. Persistence configuration 复制链接链接已复制到粘贴板!
Although persistence is not used by default, the dependencies needed are available in the runtime directory as jar files.
Persistence is defined per session and you can define it either using the JBPMHelper
class after you create a session or using the JPAKnowledgeService
to create your session. The latter option provides more flexibility, while JBPMHelper
has a method to create a session, and uses a configuration file to configure this session.
15.4.2. Configuring persistence using JBPMHelper 复制链接链接已复制到粘贴板!
To configure persistence of your session using JBPMHelper, do the following:
Define your application to use an appropriate JBPMHelper session constructor:
-
KieSession ksession = JBPMHelper.newKieSession(kbase);
-
KieSession ksession = JBPMHelper.loadKieSession(kbase, sessionId);
-
Configure the persistence in the
jBPM.properties
file.Example 15.1. A sample jBPM.properties file with persistence for the in-memory H2 database
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Any invocations on the session will now trigger the persistence process.
Make sure the datasource is up and running on engine start. If you are running the in-memory H2 database, you can start the database from your application using the JBPMHelper.startH2Server();
method call and register it with the engine using JBPMHelper.setupDataSource();
method call.
To create your knowledge session and configure its persistence using JPAKnowledgeService, do the following:
Define your application to use the knowledge session created by JPAKnowledgeService:
Define the session based on a knowledge base, a knowledge session configuration, and an environment. The environment must contain a reference to your Entity Manager Factory:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the session based on a specific session id.
// recreate the session from database using the sessionId ksession = JPAKnowledgeService.loadKieSession(sessionId, kbase, null, env );
// recreate the session from database using the sessionId ksession = JPAKnowledgeService.loadKieSession(sessionId, kbase, null, env );
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Configure the persistence in the
META-INF/persistence.xml
file: configure JPA to use Hibernate and the respective database.Information on how to configure data source on your application server should be available in the documentation delivered with the application server. For this information for JBoss Enterprise Application Platform, see the Administration and Configuration Guide for this product.
Example 15.2. A sample persistence.xml file with persistence for an H2 data source jdbc/jbpm-ds
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Any invocations on the session will now trigger the persistence process.
Make sure the datasource is up and running on engine start. If you are running the in-memory H2 database, you can start the database from your application using the JBPMHelper.startH2Server();
method call and register it with the engine using JBPMHelper.setupDataSource();
method call.
If you are running JBoss BPM Suite in a simple Java environment, your data source configuration will be similar to the following: