Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, so here goes a little tutorial to configure persistence in JBPM, using a MySQL database and JBoss AS:</p> <p>1) Create a META-INF folder under your src/main/java folder</p> <p>2) Create persistence.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence version="1.0" 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" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"&gt; &lt;persistence-unit name="your_unit_name" transaction-type="JTA"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;jta-data-source&gt;java:/your_data_source_name&lt;/jta-data-source&gt; &lt;mapping-file&gt;META-INF/JBPMorm.xml&lt;/mapping-file&gt; &lt;mapping-file&gt;META-INF/ProcessInstanceInfo.hbm.xml&lt;/mapping-file&gt; &lt;!-- The tables that will be created in your specified sql schema --&gt; &lt;class&gt;org.drools.persistence.info.SessionInfo&lt;/class&gt; &lt;class&gt;org.jbpm.persistence.processinstance.ProcessInstanceInfo&lt;/class&gt; &lt;class&gt;org.drools.persistence.info.WorkItemInfo&lt;/class&gt; &lt;properties&gt; &lt;property name="hibernate.default_schema" value="your_schema_name" /&gt; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /&gt; &lt;property name="hibernate.connection.autocommit" value="false" /&gt; &lt;property name="hibernate.max_fetch_depth" value="3"/&gt; &lt;property name="hibernate.hbm2ddl.auto" value="create" /&gt; &lt;property name="hibernate.show_sql" value="false" /&gt; &lt;property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>3) Create orm.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" version="1.0"&gt; &lt;named-query name="ProcessInstancesWaitingForEvent"&gt; &lt;query&gt; select processInstanceInfo.processInstanceId from ProcessInstanceInfo processInstanceInfo where :type in elements(processInstanceInfo.eventTypes) &lt;/query&gt; &lt;/named-query&gt; &lt;/entity-mappings&gt; </code></pre> <p>4) Create ProcessInstanceInfo.hbm.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" &gt; &lt;hibernate-mapping package="org.jbpm.persistence.processinstance"&gt; &lt;!-- access="field" for fields that have no setter methods --&gt; &lt;class name="ProcessInstanceInfo" table="ProcessInstanceInfo"&gt; &lt;id name="processInstanceId" type="long" column="InstanceId"&gt; &lt;generator class="native" /&gt; &lt;/id&gt; &lt;version name="version" type="integer" unsaved-value="null" access="field"&gt; &lt;column name="OPTLOCK" not-null="false" /&gt; &lt;/version&gt; &lt;property name="processId" access="field" /&gt; &lt;property name="startDate" type="timestamp" access="field" /&gt; &lt;property name="lastReadDate" type="timestamp" access="field" /&gt; &lt;property name="lastModificationDate" type="timestamp" access="field" /&gt; &lt;property name="state" type="integer" not-null="true" access="field" /&gt; &lt;property name="processInstanceByteArray" type="org.hibernate.type.PrimitiveByteArrayBlobType" column="processInstanceByteArray" access="field" length="2147483647" /&gt; &lt;set name="eventTypes" table="EventTypes" access="field" &gt; &lt;key column="InstanceId"/&gt; &lt;element column="element" type="string"/&gt; &lt;/set&gt; &lt;!-- NOT mapping [processInstance] field because field is transient --&gt; &lt;!-- NOT mapping [env] field because field is transient --&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>5) Now you have to define your datasource. I use JBoss5, and this version of JBoss will read any file with the pattern *-ds.xml as being the definition of your datasource. You have to put this file in your deploy folder (and you may notice there's already a datasource file there, but there will be no conflicts). If you're using JBoss7, there's a different way to define the DS - I suppose this might be helpful <a href="https://community.jboss.org/wiki/DataSourceConfigurationInAS7" rel="noreferrer">https://community.jboss.org/wiki/DataSourceConfigurationInAS7</a>.</p> <p>Anyway, here's what your yourDS-ds.xml should look like:</p> <pre><code>&lt;datasources&gt; &lt;local-tx-datasource&gt; &lt;jndi-name&gt;jdbc/your_datasource_name&lt;/jndi-name&gt; &lt;connection-url&gt;your_db_url&lt;/connection-url&gt; &lt;driver-class&gt;com.mysql.jdbc.Driver&lt;/driver-class&gt; &lt;user-name&gt;your_user&lt;/user-name&gt; &lt;password&gt;your_pass&lt;/password&gt; &lt;min-pool-size&gt;5&lt;/min-pool-size&gt; &lt;max-pool-size&gt;20&lt;/max-pool-size&gt; &lt;idle-timeout-minutes&gt;5&lt;/idle-timeout-minutes&gt; &lt;/local-tx-datasource&gt; &lt;/datasources&gt; </code></pre> <p>6) The above instructions are enough to at least create the persistence tables in the database. When you eventually start using tasks in JBPM, it may be required to create a Taskorm.xml file (google it, it's too long). I'm not sure if it's necessary, but I have it anyway.</p> <p>7) Finally, just call your persistence unit in Java through the EntityManagerFactory, create your environment and start a new session. The persistence data should be automatically saved to the DB. </p> <p>Hope this was helpful. Cheers!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload