Chapter 14. Persistence
Binary persistence, or marshaling, converts the state of the process instance into a binary data set. Binary persistence is a mechanism used to store and retrieve information persistently. The same mechanism is also applied to the session state and work item states.
When you enable persistence of a process instance:
- Red Hat Decision Manager transforms the process instance information into binary data. Custom serialization is used instead of Java serialization for performance reasons.
- The binary data is stored together with other process instance metadata, such as process instance ID, process ID, and the process start date.
The session can also store other forms of state, such as the state of timer jobs, or data required for business rules evaluation. Session state is stored separately as a binary data set along with the ID of the session and metadata. You can restore the session state by reloading a session with given ID. Use ksession.getId() to get the session ID.
Red Hat Decision Manager will persist the following when persistence is configured:
- Session state: This includes the session ID, date of last modification, the session data that business rules would need for evaluation, state of timer jobs.
- Process instance state: This includes the process instance ID, process ID, date of last modification, date of last read access, process instance start date, runtime data (the execution status including the node being executed, variable values, and other process instance data) and the event types.
- Work item runtime state: This includes the work item ID, creation date, name, process instance ID, and the work item state itself.
Based on the persisted data, you can restore the state of execution of all running process instances in case of failure or to temporarily remove running instances from memory and restore them later.
14.1. Configuring safe points
To allow persistence, add the jbpm-persistence JAR files to the classpath of your application and configure the decision engine to use persistence. The decision engine automatically stores the runtime state in the storage when the decision engine reaches a safe point.
Safe points are points where the process instance has paused. When a process instance invocation reaches a safe point in the decision engine, the decision engine stores any changes to the process instance as a snapshot of the process runtime data. However, when a process instance is completed, the persisted snapshot of process instance runtime data is automatically deleted.
If a failure occurs and you need to restore the decision engine runtime from the storage, the process instances are automatically restored and their execution resumes so there is no need to reload and trigger the process instances manually.
The runtime persistence data is to be considered internal to the decision engine. You should not access persisted runtime data or modify them directly as this might have unexpected side effects.
For more information about the current execution state, refer to the history log. Query the database for runtime data only if absolutely necessary.
14.2. Session persistence entities
Sessions are persisted as SessionInfo entities. These persist the state of the runtime KIE session, and store the following data:
Table 14.1. SessionInfo
| Field | Description | Nullable |
|---|---|---|
|
| The primary key. | NOT NULL |
|
| The last time that entity was saved to a database. | |
|
| The state of a session. | NOT NULL |
|
| The session start time. | |
|
| A version field containing a lock value. |
14.3. Process instance persistence entities
Process instances are persisted as ProcessInstanceInfo entities, which persist the state of a process instance on runtime and store the following data:
Table 14.2. ProcessInstanceInfo
| Field | Description | Nullable |
|---|---|---|
|
| The primary key. | NOT NULL |
|
| The last time that the entity was saved to a database. | |
|
| The last time that the entity was retrieved from the database. | |
|
| The ID of the process. | |
|
| The state of a process instance in form of a binary data set. | NOT NULL |
|
| The start time of the process. | |
|
| An integer representing the state of a process instance. | NOT NULL |
|
| A version field containing a lock value. |
ProcessInstanceInfo has a 1:N relationship to the EventTypes entity.
The EventTypes entity contains the following data:
Table 14.3. EventTypes
| Field | Description | Nullable |
|---|---|---|
|
|
A reference to the | NOT NULL |
|
| A finished event in the process. |
14.4. Work item persistence entities
Work items are persisted as workiteminfo entities, which persist the state of the particular work item instance on runtime and store the following data:
Table 14.4. WorkItemInfo
| Field | Description | Nullable |
|---|---|---|
|
| The primary key. | NOT NULL |
|
| The name of the work item. | |
|
| The (primary key) ID of the process. There is no foreign key constraint on this field. | NOT NULL |
|
| The state of a work item. | NOT NULL |
|
| A version field containing a lock value. | |
|
| The work item state in as a binary data set. | NOT NULL |
14.5. Correlation key entities
The CorrelationKeyInfo entity contains information about the correlation key assigned to the given process instance. This table is optional. Use it only when you require correlation capabilities.
Table 14.5. CorrelationKeyInfo
| Field | Description | Nullable |
|---|---|---|
|
| The primary key. | NOT NULL |
|
| The assigned name of the correlation key. | |
|
| The ID of the process instance which is assigned to the correlation key. | NOT NULL |
|
| A version field containing a lock value. |
The CorrelationPropertyInfo entity contains information about correlation properties for a correlation key assigned the process instance.
Table 14.6. CorrelationPropertyInfo
| Field | Description | Nullable |
|---|---|---|
|
| The primary key. | NOT NULL |
|
| The name of the property. | |
|
| The value of the property. | NOT NULL |
|
| A version field containing a lock value. | |
|
| A foreign key mapped to the correlation key. | NOT NULL |
14.6. Context mapping entity
The ContextMappingInfo entity contains information about the contextual information mapped to a KieSession. This is an internal part of RuntimeManager and can be considered optional when RuntimeManager is not used.
Table 14.7. ContextMappingInfo
| Field | Description | Nullable |
|---|---|---|
|
| The primary key. | NOT NULL |
|
| The context identifier. | NOT NULL |
|
|
The | NOT NULL |
|
| A version field containing a lock value. | |
|
| Holds the identifier of the deployment unit that the given mapping is associated with |
14.7. Pessimistic Locking Support
The default locking mechanism for persistence of processes is optimistic. With multi-thread high concurrency to the same process instance, this locking strategy can result in bad performance.
This can be changed at runtime to allow the user to set locking on a per process basis and to allow it to be pessimistic (the change can be made at a per KIE Session level or Runtime Manager level as well and not just at the process level).
To set a process to use pessimistic locking, use the following configuration in the runtime environment:
import org.kie.api.runtime.Environment; import org.kie.api.runtime.EnvironmentName; import org.kie.api.runtime.manager.RuntimeManager; import org.kie.api.runtime.manager.RuntimeManagerFactory; ... env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true); 1 RuntimeManager manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment); 2

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.