4 Replies Latest reply on Jan 5, 2011 8:05 PM by Kris Verlaenen

    Configuring JBPM 5 with other databases

    krishnendu kunti Newbie

      Hi All

       

      How to configure JBPM 5 with other databases? Unlike JBPM 4.4 the build script does not have any property to indicate DB choice... any halp is appreciated.

       

      Thank you

      Krish

        • 1. Re: Configuring JBPM 5 with other databases
          Kris Verlaenen Master

          Yes, the script does not yet allow this kind of simply configuration yet.

          You can simply change the persistence.xml configuration file according to your database though, in

          https://github.com/krisv/jbpm/blob/master/jbpm-installer/db/persistence.xml

          change the dialect

          and in

          https://github.com/krisv/jbpm/blob/master/jbpm-installer/db/testDS1-ds.xml

          change the url, driver class, username and password

          And make sure you put your lib with the driver class in jbpm-installer/db/driver

           

          You'll need to rerun ant install.demo for the changes to take effect.

           

          Any contributions to the script to make this easier are always welcome

           

          Kris

          • 2. Re: Configuring JBPM 5 with other databases
            krishnendu kunti Newbie

            hi Kris

             

            Thank you , also inorder to make the human task to work with ones' external DB the persistence.xml in jbpm-human-task-5.0-CR1.jar needs to be modified.

             

            One correction from my end... I am trying to run JBPM 5.0+ Human task in eclipse with mysql database without having to go through datasource... hence I changed this file.

             

            All the same I am yet to figure out which other files related to JBPM persistence should be changed so that process state is captured in database as well.

             

            Thanks a ton

            Krish

            • 3. Re: Configuring JBPM 5 with other databases
              krishnendu kunti Newbie

              Hi

               

              Further on this thread... (running from eclipse) I am getting the following stacktrace..

               


              java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException
              ....

               

              Caused by: java.lang.reflect.InvocationTargetException
              ...
              Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: Unable to load class: org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory

               

              ...
              by: java.lang.ClassNotFoundException: Unable to load class: org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory

               

              on bit of an investigation looks like these classes are available in drools-xx--5.1.1 but not there in drools-xx--5.2.0.. all the same on e cant' work with drools-xx5.1.1 as  some of the methods are missing which are required for creation of knowledge session.

               


              Including my persistence.xml and java runner class... please have a look....

               

              It will be a big help if someone can share some tips/code... to show it works..

               

              -----------

               

              package com.sw.test;

               

              import java.util.HashMap;
              import java.util.Map;

               

              import javax.persistence.EntityManagerFactory;
              import javax.persistence.Persistence;

               

              import org.drools.KnowledgeBase;
              import org.drools.KnowledgeBaseFactory;
              import org.drools.builder.KnowledgeBuilder;
              import org.drools.builder.KnowledgeBuilderFactory;
              import org.drools.builder.ResourceType;
              import org.drools.compiler.BPMN2ProcessFactory;
              import org.drools.compiler.ProcessBuilderFactory;
              import org.drools.io.ResourceFactory;
              import org.drools.logger.KnowledgeRuntimeLogger;
              import org.drools.logger.KnowledgeRuntimeLoggerFactory;
              import org.drools.marshalling.impl.ProcessMarshallerFactory;
              import org.drools.persistence.jpa.JPAKnowledgeService;
              import org.drools.runtime.Environment;
              import org.drools.runtime.EnvironmentName;
              import org.drools.runtime.StatefulKnowledgeSession;
              import org.drools.runtime.process.ProcessRuntimeFactory;
              import org.jbpm.bpmn2.BPMN2ProcessProviderImpl;
              import org.jbpm.marshalling.impl.ProcessMarshallerFactoryServiceImpl;
              import org.jbpm.process.builder.ProcessBuilderFactoryServiceImpl;
              import org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl;
              import org.jbpm.process.workitem.wsht.WSHumanTaskHandler;

               

              public class MyProcesstest {

               

                  /**
                   * @param args
                   */
                  public static void main(String[] args) {

               

                      try {
                          KnowledgeBase kbase = readKnowledgeBase();
                     
                      EntityManagerFactory emf =
                          Persistence.createEntityManagerFactory( "org.jbpm.persistence.my" );
                          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();
                                 
                         
                                  KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);
                                  ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new WSHumanTaskHandler());
                                  // start a new process instance
                                  Map<String, Object> params = new HashMap<String, Object>();
                                  params.put("employee", "krisv");
                                  ksession.startProcess("com.sample.evaluation", params);
                         
                      } catch (Exception e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }

               

                  }
                 
                  private static KnowledgeBase readKnowledgeBase() throws Exception {
                      ProcessBuilderFactory.setProcessBuilderFactoryService(new ProcessBuilderFactoryServiceImpl());
                      ProcessMarshallerFactory.setProcessMarshallerFactoryService(new ProcessMarshallerFactoryServiceImpl());
                      ProcessRuntimeFactory.setProcessRuntimeFactoryService(new ProcessRuntimeFactoryServiceImpl());
                      BPMN2ProcessFactory.setBPMN2ProcessProvider(new BPMN2ProcessProviderImpl());
                      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
                      kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"), ResourceType.BPMN2);
                      return kbuilder.newKnowledgeBase();
                  }
              }
              ------------------------

               

              <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
              <persistence version="1.0"
                           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"
                           xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                           xmlns="http://java.sun.com/xml/ns/persistence">
                <persistence-unit name="org.jbpm.persistence.my">
                    <provider>org.hibernate.ejb.HibernatePersistence</provider>

               

              <class>org.drools.persistence.session.SessionInfo</class>
              <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
              <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
                 
                  <properties>
                    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
                    <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jbpmdb" />
                    <property name="hibernate.connection.username" value="root"/>
                    <property name="hibernate.connection.password" value="admin"/>
                    <property name="hibernate.connection.autocommit" value="false" />
                    <property name="hibernate.max_fetch_depth" value="3"/>
                    <property name="hibernate.hbm2ddl.auto" value="create" />
                    <property name="hibernate.show_sql" value="false" />
                  </properties>
                </persistence-unit>
              </persistence>
              -----------------------------

              • 4. Re: Configuring JBPM 5 with other databases
                Kris Verlaenen Master

                In jBPM 5.0 CR1 you still need to configure Drools to use jBPM5 instead of the old Drools Flow (note that this is no longer necessary in the latest jBPM5 snapshot as Drools has now also updated to jBPM5), here is how you should create your session (with JPA persistence):

                 

                        Properties properties = new Properties();
                        properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
                        properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
                        KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
                        return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);

                 

                In jBPM5 snapshot, you can just use what you were using.

                 

                Kris