2 Replies Latest reply on May 23, 2010 10:17 PM by rebody

    JBPM4.3 Integration with Spring3.0.1 and Hibernate

      I wanted to create a basic standalone application as a test environment for JBPM 4.3 and spring before I used it in my application. So I had the following configuration

       

      I am using oracle 10g DBMS, Hibernate 3.x, Spring 3.0.1 Release with JBPM 4.3. Here goes my configuration

       

      jbpm.cfg.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <jbpm-configuration spring="enabled">
      <process-engine-context>
          <repository-service />
          <repository-cache />
      <execution-service />
      <history-service />
      <management-service />
      <identity-service />
      <task-service />
      <command-service name="txRequiredCommandService">
           <retry-interceptor />
           <environment-interceptor />
           <spring-transaction-interceptor current="true"/>
      </command-service>
      <object>
             <field name="commandService">
                  <ref object="txRequiredCommandService" />
             </field>
      </object>
      <object init="eager" />
      <transaction-context>
      <repository-session />
      <db-session />
      <message-session />
      <timer-session />
      <history-sessions/>
      <hibernate-session current="true" />
      </transaction-context>
      </process-engine-context>
      </jbpm-configuration>
      
      
      

       

      and my spring application context configuration looks like

       

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
           xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                                         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                                         http://www.springframework.org/schema/util
                                         http://www.springframework.org/schema/util/spring-util-3.0.xsd
                                         http://www.springframework.org/schema/context
                                         http://www.springframework.org/schema/context/spring-context-3.0.xsd
                                         http://www.springframework.org/schema/util
                                         http://www.springframework.org/schema/util/spring-util-3.0.xsd
                                         http://www.springframework.org/schema/aop
                                         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
                                         http://www.springframework.org/schema/tx
                                         http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
      
           <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper" />
                
      
           <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
      
           <context:annotation-config />
           <tx:advice id="txAdvice" transaction-manager="transactionManager">
                <tx:attributes>
                     <tx:method propagation="REQUIRED" name="*" />
                </tx:attributes>
           </tx:advice>
           
           <!--<aop:config>
               <aop:pointcut id="processDeployer" expression="execution(* com.jbpm.DeploymentService.*(..))"/>
               <aop:advisor advice-ref="txAdvice" pointcut-ref="deployProcess"/>
             </aop:config>
             
           --><bean id="abstractJbpmProcess" class="com.jbpm.utils.AbstractJbpmProcess" abstract="true">
                <property name="processEngine" ref="processEngine"/>
           </bean>
           
           <bean id="deploymentService" class="com.jbpm.impl.DeploymentServiceImpl"
                parent="abstractJbpmProcess" />
      </beans>
      

       

      So I can use up my processEngine in whichever service I want. So created a simple process definition as shown below

       

      <?xml version="1.0" encoding="UTF-8"?>
      
      <process name="GetHomeProcess" xmlns="http://jbpm.org/4.3/jpdl">
      
         <start g="16,102,48,48">
            <transition to="fork"/>
         </start>
         
         <fork g="96,102,48,48" name="fork">
            <transition g="120,41:" to="send email"/>
            <transition to="call ppl"/>
            <transition g="120,213:" to="book tickets"/>
         </fork>
         
         <state g="176,16,149,52" name="send email">
            <transition g="606,41:" to="final join"/>
         </state>
         
         <state g="176,100,149,52" name="call ppl">
            <transition g="377,126:" to="shipping join"/>
         </state>
         
         <state g="176,184,149,58" name="book tickets">
            <transition g="378,213:" to="shipping join"/>
         </state>
         
         <join g="353,145,48,48" name="shipping join">
            <transition to="watch movie"/>
         </join>
         
         <state g="431,140,148,52" name="watch movie">
            <transition g="607,165:" to="final join"/>
         </state>
         
         <join g="583,73,48,48" name="final join">
            <transition to="end"/>
         </join>
         
         <end g="666,74,48,48" name="end"/>
      
      </process>
      

       

      The problem would arise when I try to deploy the process

       

              @Test
           public void testProcessInstantiator() throws FileNotFoundException, JbpmAccessException{
                String deploymendId= deployProcess();
                if(deploymentService.isProcessDeployed("GetHomeProcess")==false){
                     String deploymendId2= deployProcess();
                     System.out.println("Process 2 deployed = "+deploymendId2);
                }
                System.out.println("dep Id = "+deploymendId);
                
           }
           
           private String deployProcess() throws FileNotFoundException, JbpmAccessException{
                return deploymentService.deployProcess("process-defs/HomeProc.jpdl.xml");
           }
      

       

      Deployment service here just helps me deploy the process using JBPM APIs. Doing this shows up an error stack trace as shown

       

      10:47:35,340 FST | [WireContext] creating process-engine
      10:47:35,340 FIN | [WireContext] eagerly initializing org.jbpm.pvm.internal.id.DatabaseIdComposer
      10:47:35,340 FST | [WireContext] constructing org.jbpm.pvm.internal.id.DatabaseIdComposer
      10:47:35,355 FST | [WireContext] initializing org.jbpm.pvm.internal.id.DatabaseIdComposer
      10:47:35,355 FST | [WireContext] constructing txRequiredCommandService
      10:47:35,355 FST | [WireContext] initializing txRequiredCommandService
      10:47:35,355 FST | [SpringProcessEngine] opening jbpm-springPvmEnvironment[31639999]
      10:47:35,355 FST | [WireContext] creating transaction
      10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in transaction 1108447
      10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in process-engine 22106538
      10:47:35,449 FST | [WireContext] org.hibernate.Session not found in transaction 1108447
      10:47:35,449 FST | [WireContext] org.hibernate.Session not found in process-engine 22106538
      ### EXCEPTION ###########################################
      10:47:35,449 INF | [DefaultCommandService] exception while executing command org.jbpm.pvm.internal.cmd.CheckDbCmd@18b9a72
      org.jbpm.api.JbpmException: no org.hibernate.Session in current environment
           at org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:204)
           at org.jbpm.pvm.internal.env.EnvironmentImpl.getFromCurrent(EnvironmentImpl.java:190)
           at org.jbpm.pvm.internal.cmd.CheckDbCmd.execute(CheckDbCmd.java:44)
           at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
           at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45)
           at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
           at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:55)
           at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
           at org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
           at org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
           at org.jbpm.pvm.internal.processengine.ProcessEngineImpl.checkDb(ProcessEngineImpl.java:152)
           at org.jbpm.pvm.internal.processengine.SpringProcessEngine.create(SpringProcessEngine.java:70)
           at org.jbpm.pvm.internal.cfg.ConfigurationImpl.buildProcessEngine(ConfigurationImpl.java:92)
           at org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine(SpringHelper.java:47)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
           at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:540)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:964)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:870)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
           at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
           at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
           at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
           at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
           at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
           at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562)
           at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
           at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
           at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
           at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
           at com.testcases.TestProcessTransaction.setUpBeforeClass(TestProcessTransaction.java:27)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
           at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
           at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
           at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
           at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
           at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
           at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
           at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      ### EXCEPTION ###########################################
      10:47:35,449 FST | [WireContext] closing transaction...
      10:47:35,449 FST | [BasicEnvironment] closing PvmEnvironment[31639999]
      10:47:35,449 FST | [PvmEnvironment] closed PvmEnvironment[31639999]
      10:47:35,496 INF | [SessionFactoryImpl] closing
      

       

      I want every transaction of JBPM to use Spring created transaction, which looks like is happening. If you notice the log statements shown before the stack trace.

       

      10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in transaction 1108447
      10:47:35,355 FST | [WireContext] org.springframework.transaction.PlatformTransactionManager not found in process-engine 22106538
      10:47:35,449 FST | [WireContext] org.hibernate.Session not found in transaction 1108447
      10:47:35,449 FST | [WireContext] org.hibernate.Session not found in process-engine 22106538
      

       

      I want to know why this error is showing up. Am I missing anything in my configuration? Is there any documentation or references on how the environments are being used in JBPM? Or is there any way in which I can put the session so that this stand alone application finds it.

       

      PS: I have also attached my Maven POM.xml, which might help you see the jar dependencies in the project

       

      Thanks,

      Satish