11 Replies Latest reply on Oct 16, 2009 1:52 PM by apollo11

    Problem configuring jBPM4 with Spring

    bogdanj

      Hi

      I have a problem related to configuring jBPM 4 and Spring.

      Here is jbpm.cfg.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <jbpm-configuration>
      
       <import resource="jbpm.jpdl.cfg.xml" />
       <import resource="jbpm.identity.cfg.xml" />
       <import resource="jbpm.jobexecutor.cfg.xml" />
      
       <process-engine-context>
       <repository-service />
       <repository-cache />
       <execution-service />
       <history-service />
       <management-service />
       <identity-service />
       <task-service />
      
       <!-- Here we needed to change the transaction interceptor to spring-transaction-interceptor -->
       <command-service>
       <spring-transaction-interceptor />
       <retry-interceptor type="jta" />
       <environment-interceptor />
       </command-service>
      
       <!-- Added spring as read-context -->
       <script-manager default-expression-language="juel"
       default-script-language="juel"
       read-contexts="execution, environment, process-engine, spring"
       write-context="">
       <script-language name="juel"
       factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
       </script-manager>
      
       <authentication />
      
       <id-generator />
       <types resource="jbpm.variable.types.xml" />
      
       <address-resolver />
      
       <business-calendar>
       <monday hours="9:00-12:00 and 12:30-17:00" />
       <tuesday hours="9:00-12:00 and 12:30-17:00" />
       <wednesday hours="9:00-12:00 and 12:30-17:00" />
       <thursday hours="9:00-12:00 and 12:30-17:00" />
       <friday hours="9:00-12:00 and 12:30-17:00" />
       <holiday period="01/07/2008 - 31/08/2008" />
       </business-calendar>
      
       <mail-template name='task-notification'>
       <to users="${task.assignee}" />
       <subject>${task.name}</subject>
       <text><![CDATA[Hi ${task.assignee},
      Task "${task.name}" has been assigned to you.
      ${task.description}
      
      Sent by JBoss jBPM
      ]]></text>
       </mail-template>
      
       <mail-template name='task-reminder'>
       <to users="${task.assignee}" />
       <subject>${task.name}</subject>
       <text><![CDATA[Hey ${task.assignee},
      Do not forget about task "${task.name}".
      ${task.description}
      
      Sent by JBoss jBPM
      ]]></text>
       </mail-template>
      
      
      
       </process-engine-context>
      
       <transaction-context>
       <transaction type="jta" />
      
       <repository-session />
       <db-session />
      
       <message-session />
       <timer-session />
       <history-session />
       <mail-session>
       <mail-server>
       <session-properties resource="jbpm.mail.properties" />
       </mail-server>
       </mail-session>
      
       <!-- Need to set explicitly that we don't want jbpm to create sessions -->
       <hibernate-session current="true" />
       </transaction-context>
      </jbpm-configuration>
      


      In Spring applicationContext I have defined the following

      <!--
       jBPM related beans
       -->
      
       <bean id="jbpmConfiguration" class="org.jbpm.pvm.internal.cfg.SpringConfiguration">
       <constructor-arg value="jbpm.cfg.xml" />
       </bean>
      
       <bean id="processEngine" factory-bean="jbpmConfiguration" factory-method="buildProcessEngine" />
       <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
       <bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />


      When trying to execute something like:

      NewDeployment deployment = repositoryService.createDeployment();
      deployment.addResourceFromClasspath("com/webmedia/bes/jbpm/hello-world.jpdl.xml");
      deployment.deploy();
      


      I end up with:


      by: org.jbpm.api.JbpmException: no environment for managing hibernate transaction
       at org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:53)
       at org.jbpm.pvm.internal.repository.DeploymentImpl.deploy(DeploymentImpl.java:89)
       at com.webmedia.bes.web.action.BudgetsBrowser.browse(BudgetsBrowser.java:87)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)


      I guess I am missing something obvious in the configuration. It wouldn't be the first time, if somebody can help, I would be very thankful.

        • 1. Re: Problem configuring jBPM4 with Spring
          ainze

          try



          <command-service>
           <retry-interceptor />
           <environment-interceptor />
           <spring-transaction-interceptor />
           </command-service>


          The environment-interceptor will expose the environment. Now the spring transaction interceptor is running before any environment is exposed.

          KR,
          Andries

          • 2. Re: Problem configuring jBPM4 with Spring
            ziglee

            My case is a little diferent. I'm using JPA (hibernate implementation) so I would like to know how can I stop depending on jbpm.hibernate.cfg.xml.

            I tried to expose my sessionFactory through this bean:

            <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
             p:dataSource-ref="dataSource">
             <property name="jpaVendorAdapter">
             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
             <property name="showSql" value="true" />
             <property name="generateDdl" value="true" />
             <property name="databasePlatform" value="${hibernate.dialect}" />
             </bean>
             </property>
            </bean>
            
            <bean id="sessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory"/>


            and used

            <process-engine-context>
             <command-service>
             <retry-interceptor />
             <environment-interceptor />
             <spring-transaction-interceptor />
             </command-service>
            </process-engine-context>
            
            <transaction-context>
             <transaction />
             <hibernate-session current="true" />
            </transaction-context>
            


            but all I got was:

            Caused by: org.hibernate.HibernateException: No CurrentSessionContext configured!



            Can somebody help me?

            Thanks in advance!

            • 3. Re: Problem configuring jBPM4 with Spring

              try to add current=true to the spring interceptor.

               <command-service>
               <retry-interceptor />
               <environment-interceptor />
               <spring-transaction-interceptor current="true" />
               </command-service>


              • 4. Re: Problem configuring jBPM4 with Spring
                ziglee

                When using:

                <command-service>
                 <retry-interceptor />
                 <environment-interceptor />
                 <spring-transaction-interceptor current="true" />
                </command-service>


                Results in:
                No existing transaction found for transaction marked with propagation 'mandatory'


                • 5. Re: Problem configuring jBPM4 with Spring
                  ziglee

                  To support the transaction need, I'm using:

                  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
                   p:entityManagerFactory-ref="entityManagerFactory" />
                  <tx:annotation-driven transaction-manager="transactionManager" />


                  and I've placed the @Transactional annotation where data is being manipulated:

                  @Transactional
                  public void afterPropertiesSet() throws Exception {
                   for(String processDefinition : processDefinitions){
                   repositoryService.createDeployment().addResourceFromClasspath(processDefinition).deploy();
                   }
                  }
                  


                  ...but still getting...

                  No existing transaction found for transaction marked with propagation 'mandatory'


                  • 6. Re: Problem configuring jBPM4 with Spring

                    You should remove the current="true" attribute.

                    <command-service>
                    <retry-interceptor />
                    <environment-interceptor />
                    <spring-transaction-interceptor />
                    </command-service>

                    • 7. Re: Problem configuring jBPM4 with Spring
                      ziglee

                      Removing the current="true" attribute:

                      Caused by: org.hibernate.HibernateException: No CurrentSessionContext configured!


                      • 8. Re: Problem configuring jBPM4 with Spring
                        • 9. Re: Problem configuring jBPM4 with Spring
                          jbarrez

                          Are you using JPA or Hibernate? In the first case, these kind of errors are to be expected since we've not yet implemented JPA integration.

                          • 10. Re: Problem configuring jBPM4 with Spring
                            ziglee

                            JPA

                            • 11. Re: Problem configuring jBPM4 with Spring

                              what is the reason to set the hibernate-session current="true" in the jbmp.cfg.xml file?

                              <!-- Need to set explicitly that we don't want jbpm to create sessions-->
                              <hibernate-session current="true"


                              I got the following exception when running either in Tomcat or JUnit tests. I was trying to retrieve the subtasks of a task.

                              Oct 16, 2009 1:49:37 PM org.hibernate.LazyInitializationException
                              SEVERE: could not initialize proxy - no Session
                              org.hibernate.LazyInitializationException: could not initialize proxy - no Session
                              at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)
                              at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
                              at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
                              at org.jbpm.pvm.internal.task.TaskImpl_$$_javassist_39.getSubTasks(TaskImpl_$$_javassist_39.java)



                              However, if I set the value to "false", then it works but occasinally the application hangs and I cannot find the causes.