Advertise with us

Our eBooks

Configuring jBPM to use a non-default Database

jBPM out of the box uses H2 database to store the state of processes using a file located under $JBOSS_HOME/standalone/data/jbpm-db .

In order to switch to another database, you can use any of the following scripts which are available in $JBOSS_HOME/bin.

For MySQL:

$ ./jboss-cli.sh --file=jbpm-mysql-config.cli      (Unix / Linux)

For PostgreSQL:

$ ./jboss-cli.sh --file=jbpm-postgres-config.cli      (Unix / Linux)

The above commands needs to be executed when the server is stopped as an embedded server process will be used to update the configuration.

These scripts assume that database is installed and some default configuration is present:

  • host → localhost
  • port → 3306 for MySQL and 5432 for PostgreSQL
  • database name → jbpm
  • user name → jbpm

Changing jBPM to PostgreSQL

As an example, we will show how to change the default database to PostgreSQL. Start PostgreSQL for example with Docker:

 docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 --name jbpm -e POSTGRES_USER=jbpm -e POSTGRES_PASSWORD=jbpm -e POSTGRES_DB=jbpm -p 5432:5432 postgres:10.5

Then, run the jbpm-postgres-config.cli

$ ./jboss-cli.sh --file=jbpm-postgres-config.cli      (Unix / Linux)

Now start jBPM:

$ ./standalone.sh

As you can see from the XML configuration, the datasource named "jBPMXADS" has been added:

  <xa-datasource jndi-name="java:jboss/datasources/jBPMDS" pool-name="jBPMXADS">
                    <xa-datasource-property name="ServerName">
                        localhost
                    </xa-datasource-property>
                    <xa-datasource-property name="PortNumber">
                        5432
                    </xa-datasource-property>
                    <xa-datasource-property name="DatabaseName">
                        jbpm
                    </xa-datasource-property>
                    <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                    <driver>postgres</driver>
                    <security>
                        <user-name>jbpm</user-name>
                        <password>jbpm</password>
                    </security>
                    <validation>
                        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
                        <validate-on-match>true</validate-on-match>
                        <background-validation>true</background-validation>
                        <background-validation-millis>120000</background-validation-millis>
                        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
                    </validation>
                </xa-datasource>
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                    <driver name="postgres" module="org.postgres">
                        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
                    </driver>
                </drivers>

You can also log into PostgreSQL and check that tables have been created:

jbpm=# \dt
                    List of relations
 Schema |              Name              | Type  | Owner
 public | attachment                     | table | jbpm
 public | audittaskimpl                  | table | jbpm
 public | bamtasksummary                 | table | jbpm
 public | booleanexpression              | table | jbpm
 public | casefiledatalog                | table | jbpm
 public | caseidinfo                     | table | jbpm
 public | caseroleassignmentlog          | table | jbpm
 public | content                        | table | jbpm
 public | contextmappinginfo             | table | jbpm
 public | correlationkeyinfo             | table | jbpm
 public | correlationpropertyinfo        | table | jbpm
 public | deadline                       | table | jbpm
 public | delegation_delegates           | table | jbpm
 public | deploymentstore                | table | jbpm
 public | email_header                   | table | jbpm
 public | errorinfo                      | table | jbpm
 public | escalation                     | table | jbpm
 public | eventtypes                     | table | jbpm
 public | executionerrorinfo             | table | jbpm
 public | i18ntext                       | table | jbpm
 public | nodeinstancelog                | table | jbpm
 public | notification                   | table | jbpm
 public | notification_bas               | table | jbpm
 public | notification_email_header      | table | jbpm
 public | notification_recipients        | table | jbpm
 public | organizationalentity           | table | jbpm
 public | peopleassignments_bas          | table | jbpm
 public | peopleassignments_exclowners   | table | jbpm
 public | peopleassignments_potowners    | table | jbpm
 public | peopleassignments_recipients   | table | jbpm
 public | peopleassignments_stakeholders | table | jbpm
 public | processinstanceinfo            | table | jbpm
 public | processinstancelog             | table | jbpm
 public | querydefinitionstore           | table | jbpm
 public | reassignment                   | table | jbpm
 public | reassignment_potentialowners   | table | jbpm
 public | requestinfo                    | table | jbpm
 public | sessioninfo                    | table | jbpm
 public | task                           | table | jbpm
 public | task_comment                   | table | jbpm
 public | taskdef                        | table | jbpm
 public | taskevent                      | table | jbpm
 public | taskvariableimpl               | table | jbpm
 public | variableinstancelog            | table | jbpm
 public | workiteminfo                   | table | jbpm
(45 rows)

That's all. We have just learnt how to change the default database used by jBPM.

© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.