5 Replies Latest reply on Jan 30, 2010 6:23 AM by tom42332

    JBpm 4.3 + Spring 3 transaction problem at buildProcessEngine

      When starting up JBPM using Configuration.buildProcessEngine() I get an exception

       

      org.jbpm.api.JbpmException: no jBPM DB schema: no JBPM4_EXECUTION table.   Run the create.jbpm.schema target first in the install tool.
          at org.jbpm.pvm.internal.cmd.CheckDbCmd.execute(CheckDbCmd.java:50)

       

      I put a breakpoint at CheckDbCmd at that line and found out that there is an underlying exception:

      org.hibernate.HibernateException: createQuery is not valid without active transaction

       

      However transactions are definitely enabled (Spring transactions, see stacktrace below). I've also tried a multitude of variations of configuring transaction management in jbpm, such as <hibernate-session current="true" /> and changing current to false and lots of other variations.

      I somehow have the impression it could be related to Tom Baeyens observations.

       

      Has anyone any idea how to solve this?

       

      Using JBPM 4.3, Spring 3.0.0, Hibernate 3.3.1, MSSQL Server.

       

      jbpm.cfg.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <jbpm-configuration spring="enabled">
      
           <import resource="jbpm.jobexecutor.cfg.xml" />
           <import resource="jbpm.jpdl.cfg.xml"/>
           <import resource="jbpm.bpmn.cfg.xml" />
      
           <process-engine-context>
               <repository-service />
               <repository-cache />
               <execution-service />
               <history-service />
               <management-service />
               <identity-service />
               <task-service />
                
               <string name="spring.cfg" value="jbpm/jbpm-spring-config.xml" />
       
                   <types resource="jbpm.variable.types.xml" />
      
               <object class="org.jbpm.pvm.internal.id.DatabaseDbidGenerator">
                 <field name="commandService"><ref object="newTxRequiredCommandService" /></field>
               </object>
               <object class="org.jbpm.pvm.internal.id.DatabaseIdComposer" init="eager" />
           
               <command-service name="txRequiredCommandService">
                    <skip-interceptor />
                    <retry-interceptor />
                <environment-interceptor />
                <spring-transaction-interceptor />
               </command-service>
           
               <command-service name="newTxRequiredCommandService">
                <retry-interceptor />
                <environment-interceptor policy="requiresNew" />
                <spring-transaction-interceptor policy="requiresNew" />
               </command-service>
               
           </process-engine-context>
           
      
           <transaction-context>
               <repository-session />
               <db-session />
               <message-session />
               <timer-session />
               <identity-session />
               
               <history-sessions>
                <object class="org.jbpm.pvm.internal.history.HistorySessionImpl" />
                   </history-sessions>
           
               <transaction type="spring" />
               <hibernate-session current="true" />
      

      .

       

      jbpm/spring application context:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <beans xmlns="http://www.springframework.org/schema/beans" 
                xmlns:aop="http://www.springframework.org/schema/aop" 
                xmlns:context="http://www.springframework.org/schema/context"
                xmlns:tx="http://www.springframework.org/schema/tx"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="
                http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
      
        <import resource="../properties-config.xml"/>
      
        <bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper">
             <property name="jbpmCfg" value="jbpm/jbpm.cfg.xml"/>
        </bean>
      
        <bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" />
        
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
          <property name="sessionFactory" ref="sessionFactory" />
          <property name="dataSource" ref="dataSource" />
        </bean>
      
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
          <property name="configLocation" value="classpath:/jbpm/jbpm.hibernate.cfg.xml" />
          <property name="dataSource" ref="dataSource" />
        </bean>
        
        <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
          <property name="driverClass" value="net.sourceforge.jtds.jdbc.Driver" />
          <property name="url" value="jdbc:jtds:sqlserver://${Database.server}:${Database.port}/${Database.database}" />
          <property name="username" value="${Database.user}" />
          <property name="password" value="${Database.password}" />
        </bean>
      
      </beans>
      

      .

       

      jbpm.hibernate.cfg.xml

      <?xml version="1.0" encoding="utf-8"?>
      
      <!DOCTYPE hibernate-configuration PUBLIC
                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      
      <hibernate-configuration>
          <session-factory>
              <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
               <property name="hibernate.current_session_context_class">thread</property>
              
              <mapping resource="jbpm.repository.hbm.xml" />
              <mapping resource="jbpm.execution.hbm.xml" />
              <mapping resource="jbpm.history.hbm.xml" />
              <mapping resource="jbpm.task.hbm.xml" />
              <mapping resource="jbpm.identity.hbm.xml" />
          </session-factory>
      </hibernate-configuration>
      
      
        • 1. Re: JBpm 4.3 + Spring 3 transaction problem at buildProcessEngine

          Stacktrace:


          SEVERE: Error creating bean with name 'processEngine' defined in class path resource [jbpm/jbpm-spring-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [protected org.jbpm.api.ProcessEngine org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine()] threw exception; nested exception is org.jbpm.api.JbpmException: no jBPM DB schema: no JBPM4_EXECUTION table.   Run the create.jbpm.schema target first in the install tool.
          org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine' defined in class path resource [jbpm/jbpm-spring-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [protected org.jbpm.api.ProcessEngine org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine()] threw exception; nested exception is org.jbpm.api.JbpmException: no jBPM DB schema: no JBPM4_EXECUTION table.   Run the create.jbpm.schema target first in the install tool.
               at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:551)
               at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:964)
               at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:868)
               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:557)
               at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
               at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
               at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
               at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
               at org.jbpm.pvm.internal.processengine.SpringProcessEngine.create(SpringProcessEngine.java:77)
               at org.jbpm.pvm.internal.cfg.ConfigurationImpl.buildProcessEngine(ConfigurationImpl.java:92)
               at com.test.WorkflowService.initialiseJbpmEngineServices(WorkflowService.java:90)
               at com.test.WorkflowService.startService(WorkflowService.java:66)
               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)
               at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
               at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
               at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
               at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
               at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
               at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
               at $Proxy6.startService(Unknown Source)
               at com.test.Server.startService(Server.java:402)
               at com.test.Server.startWorkflowService(Server.java:592)
               at com.test.Server.run(Server.java:161)
               at com.test.Server.main(Server.java:906)
               at com.test.Service.main(Service.java:17)
          Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [protected org.jbpm.api.ProcessEngine org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine()] threw exception; nested exception is org.jbpm.api.JbpmException: no jBPM DB schema: no JBPM4_EXECUTION table.   Run the create.jbpm.schema target first in the install tool.
               at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:158)
               at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:540)
               ... 39 more
          Caused by: org.jbpm.api.JbpmException: no jBPM DB schema: no JBPM4_EXECUTION table.   Run the create.jbpm.schema target first in the install tool.
               at org.jbpm.pvm.internal.cmd.CheckDbCmd.execute(CheckDbCmd.java:50)
               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.svc.SkipInterceptor.execute(SkipInterceptor.java:43)
               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(NativeMethodAccessorImpl.java:39)
               at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
               at java.lang.reflect.Method.invoke(Method.java:597)
               at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
               ... 40 more
          
          • 2. Re: JBpm 4.3 + Spring 3 transaction problem at buildProcessEngine

            Hi,

            Make sure you tell hibernate to create the tables,  with the property 'hibernate.hbm2ddl.auto'.

             

            Thanks

            Azarias Tomás

            • 3. Re: JBpm 4.3 + Spring 3 transaction problem at buildProcessEngine

              The DB is correctly set up and there. I'm using a separate script for creating the database schema. When I remove the following line from the hibernate config file:

              <property name="hibernate.current_session_context_class">thread</property>
              

              everything works - without proper transactions though (?) so not a solution for us.

               

              The same problem also happens when I use HSQL in-mem database and hibernate.hbm2ddl.auto set to create-drop.

              • 4. Re: JBpm 4.3 + Spring 3 transaction problem at buildProcessEngine
                saraswati.santanu

                When you are using hibernate and let spring manage the transaction then the session should be bound to the transaction and not to thread. The hibernate.current_session_context_class property should be SpringSessionContext class. This is done automatically in LocalSessionFactoryBean. So you need not do anything extra.

                 

                Making a session bound to a thread does not make it transaction aware. You can manually start and stop as many transactions as you want in a thread. In an application server you should never use thread session context - that can be dangerous. You should use JTA. And with spring you should let spring set it.

                 

                I was interested to know how did you conclude that there is no transaction when you remove current session context class as thread?

                • 5. Re: JBpm 4.3 + Spring 3 transaction problem at buildProcessEngine

                  The hibernate.current_session_context_class property should be SpringSessionContext class. This is done automatically in LocalSessionFactoryBean. So you need not do anything extra.

                  I didn't know that but it makes sense. And it works

                  What strikes me though is the fact that in the configuration files that are shipped with the jbpm4.3 distribution all have current_session_context_class set to thread including the spring-hibernate configuration file.

                   

                  Anyway, thanks a lot for your help - saved me a lot of time!

                   

                  Tom

                   

                  [Edit] your question:

                  I was interested to know how did you conclude that there is no transaction when you remove current session context class as thread?

                  When I had a process definition with a fork to multiple tasks I get an exception something like constraint violation, it cannot insert values with the same key into the execution table. However I think now this might be related to something different...