2 Replies Latest reply on Apr 29, 2011 1:37 AM by harishpandya

    jbpm 3.2.2 in Jboss AS 4.2.2 - Transaction Problems

    jaydub

      Hello,

      I have recently added jBPM to some pre-existing EJB3 stateless session beans in my EE app, running on Jboss 4.2.2GA. I must be doing something wrong, as I am unable to find any posts which seem to match my problem. Hopefully this is not too difficult to troubleshoot, as jBPM is really going to be great addition to our app. I have used http://wiki.jboss.org/wiki/Wiki.jsp?page=Jbpm32UsingCMT as a reference.

      Here is my jbpm context config:

      <jbpm-context>
       <service name="persistence" factory="org.jbpm.persistence.jta.JtaDbPersistenceServiceFactory" />
       <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
       </jbpm-context>


      Hibernate config:
      
      <hibernate-configuration>
      
       <session-factory>
      
       <!-- hibernate dialect -->
       <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
      
       <!-- Update DB Schema as needed -->
       <property name="hibernate.hbm2ddl.auto">update</property>
      
       <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
      
       <!-- DataSource properties (begin) -->
       <property name="hibernate.connection.datasource">java:/JbpmDS</property>
       <!-- DataSource properties (end) -->
      
       <!-- JTA transaction properties (begin) -->
       <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
       <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
       <!-- JTA transaction properties (end) -->
      
      
      ...
      ...


      I am able to fetch/persist jBPM data with no problem. Where I run into a problem is if I interact with jBPM, then try to persist my own entities via an entity manager from a different persistence context:

      For example:

      
      
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
      
       logger.debug("Starting a new PI in workflow " +
       procDefName + " for urlID=" + url.getUrlId());
       try
       {
       pi = jbpmContext.newProcessInstance(procDefName);
       pi.signal();
       jbpmContext.save(pi);
       }
       catch (Exception e)
       {
       logger.error("Unable to start new PI for urlId=" + url.getUrlId() +
       " in workflow " + procDefName, e);
       throw new EJBException(e);
       }
       finally
       {
       jbpmContext.close();
       }
       logger.debug("Started new jBPM process for urlId=" + url.getUrlId());
      
       // Need to track urlId -> PI, so persist the relationship.
       logger.debug("Saving process instance mapping.");
       ActiveProcessInstance activeProc =
       new ActiveProcessInstance(url.getUrlId(), pi.getId(), workflowId, procDefName);
       em.persist(activeProc);


      The final em.persist(activeProc) call causes a TransactionRequiredException. This operation saves the entity in a completely different database than jBPM is configured to use (same DB server though) So in summary, I can execute the jBPM calls, or my own entity manager persist call, but not both inside the same stateless session bean method. I did note that upon close, jBPM must be committing the JTA transaction, which causes the exception in the subsequent em.persist call.

      2008-02-20 13:49:07,923 DEBUG [org.jbpm.svc.Services] org.jbpm.svc.Services.clo
      se closing service 'persistence': org.jbpm.persistence.jta.JtaDbPersistenceServ
      ice@1026cfb
      2008-02-20 13:49:07,924 DEBUG [org.jbpm.persistence.db.DbPersistenceService] or
      g.jbpm.persistence.db.DbPersistenceService.commit committing hibernate transact
      ion org.hibernate.transaction.JTATransaction@1143d35
      2008-02-20 13:49:07,925 DEBUG [org.jbpm.JbpmContext] org.jbpm.persistence.jta.J
      taDbPersistenceService.endJtaTransaction end user JTA transaction
      2008-02-20 13:49:07,925 DEBUG [org.jbpm.JbpmContext] org.jbpm.persistence.jta.J
      taDbPersistenceService.endJtaTransaction end jta transation with COMMIT
      2008-02-20 13:49:07,936 DEBUG [org.jbpm.svc.Services] org.jbpm.svc.Services.clo
      se closing service 'tx': org.jbpm.tx.TxService@141138b


      I tried setting isTransactionEnabled to false for the persistence factory, but that did not seem to change anything. Thanks for your help and sorry if I am missing something obvious.






        • 1. Re: jbpm 3.2.2 in Jboss AS 4.2.2 - Transaction Problems
          cornhoolio22

          Hope this wokrs ;) Adjust the factory to your name...

          <jbpm-context>
           <service name="persistence">
           <factory>
           <bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
           <field name="isCurrentSessionEnabled"><true /></field>
           <field name="isTransactionEnabled"><false /></field>
           </bean>
           </factory>
           </service>
           <service name="message">
          


          isCurrentSessionEnabled true means jBPM will request Hibernate to use the current session associated with the current transaction. If there is no current transaction, an exception will be thrown stating no session is active. In this case, you may want to set this isCurrentSessionEnabled to false, and inject the current session into the JbpmContext via the JbpmContext.setSession(session) method. This will also insure that jBPM uses the same Hibernate session as other parts of your application. Note, the Hibenrate session can be injected into a stateless session bean via a persistence context, for example

          • 2. Re: jbpm 3.2.2 in Jboss AS 4.2.2 - Transaction Problems
            harishpandya

            Hi Markus,

             

            I was facing "Unable to Locate current JTA transaction" error.

            So i changed the

             

            <field name="isCurrentSessionEnabled"><true /></field>

             

            property of jbpm.cfg.sml to false.

             

            Now my jbpm transactions are not getting commited.

            I tried following thing

            • Saved process Instance
            • Inserted session manually through hibernate SessionFactory
            • Explicitally commited jbpm transaction

             

            But nothing helped me out.

            I am using JTA transaction.

             

            So can you help me.

            My jbpm.cfg.xml file is as follow

             

             

             

             

            <jbpm-configuration>

              <!--
                The default configurations can be found in org/jbpm/default.jbpm.cfg.xml
                Those configurations can be overwritten by putting this file called
                jbpm.cfg.xml on the root of the classpath and put in the customized values.
              -->

              <jbpm-context>
               <service name="persistence">
                  <factory>
                    <bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
                      <field name="isTransactionEnabled"><false /></field>
                      <field name="isCurrentSessionEnabled"><false /></field>
                    </bean>
                  </factory>
                </service>
                <service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
                <service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
                <service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
                <service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
              </jbpm-context>

              <!-- configuration resource files pointing to default configuration files in jbpm-{version}.jar -->
            <string name="resource.hibernate.cfg.xml" value="/hibernate.cfg.xml" />
               <string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
              <string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
              <string name="resource.converter" value="org/jbpm/db/hibernate/jbpm.converter.properties" />
              <string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
              <string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
              <string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
              <string name="resource.varmapping" value="org/jbpm/context/exe/jbpm.varmapping.xml" />

              <bean name="jbpm.task.instance.factory" class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl" singleton="true" />
              <bean name="jbpm.variable.resolver" class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true" />
               <bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor">
              <field name="jbpmConfiguration"> <ref bean="jbpmConfiguration"/> </field>
              <field name="name"> <string value="JbpmJobExector"/> </field>
              <field name="nbrOfThreads"> <int value="1"/> </field>
              <field name="idleInterval"> <int value="5000"/> </field>
              <field name="maxIdleInterval"> <int value="3600000"/> </field> <!-- 1 hour -->
              <field name="historyMaxSize"> <int value="20"/> </field>
              <field name="maxLockTime"> <int value="600000"/> </field> <!-- 10 minutes -->
              <field name="lockMonitorInterval"> <int value="60000"/> </field> <!-- 1 minute -->
              <field name="lockBufferTime"> <int value="5000"/> </field> <!-- 5 seconds -->
            </bean>
              <long name="jbpm.msg.wait.timout" value="5000" singleton="true" />

            </jbpm-configuration>

             

             

             

            HIbernate.cfg.xml is::>

             

            <?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.Oracle10gDialect</property>
            <property name="connection.driver_class">oracle.jdbc.xa.client.OracleXADataSource</property>

                <property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
               
            <property name="hibernate.jdbc.batch_size">0</property>
                
                 <property name="hibernate.connection.datasource">java:datasource</property>
                
              <property name="hibernate.connection.pool_size">10</property>

              <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
            <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
                 <property name="hibernate.hbm2ddl.auto">update</property>

                 <property name="hibernate.format_sql">true</property>
                <property name="hibernate.use_sql_comments">true</property>

            <property name="hibernate.show_sql">true</property>
            <property name="hibernate.current_session_context_class">managed</property>

                   <mapping resource="hibernate.extra.hbm.xml" />
                <mapping resource="hibernate.identity.hbm.xml" />

                  <mapping resource="org/jbpm/db/hibernate.types.hbm.xml" />

                   <mapping resource="org/jbpm/graph/action/MailAction.hbm.xml"/>

                   <mapping resource="org/jbpm/graph/def/ProcessDefinition.hbm.xml"/>
                <mapping resource="org/jbpm/graph/def/Node.hbm.xml"/>
                <mapping resource="org/jbpm/graph/def/Transition.hbm.xml"/>
                <mapping resource="org/jbpm/graph/def/Event.hbm.xml"/>
                <mapping resource="org/jbpm/graph/def/Action.hbm.xml"/>
                <mapping resource="org/jbpm/graph/def/SuperState.hbm.xml"/>
                <mapping resource="org/jbpm/graph/def/ExceptionHandler.hbm.xml"/>
                <mapping resource="org/jbpm/instantiation/Delegation.hbm.xml"/>

                <mapping resource="org/jbpm/graph/node/StartState.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/EndState.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/ProcessState.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/Decision.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/Fork.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/Join.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/MailNode.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/State.hbm.xml"/>
                <mapping resource="org/jbpm/graph/node/TaskNode.hbm.xml"/>

                <mapping resource="org/jbpm/context/def/ContextDefinition.hbm.xml"/>
                <mapping resource="org/jbpm/context/def/VariableAccess.hbm.xml"/>

                <!-- bytes mapping files -->
                <mapping resource="org/jbpm/bytes/ByteArray.hbm.xml"/>

                <!-- module.def mapping files -->
                <mapping resource="org/jbpm/module/def/ModuleDefinition.hbm.xml"/>

                <!-- file.def mapping files -->
                <mapping resource="org/jbpm/file/def/FileDefinition.hbm.xml"/>

                 <mapping resource="org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/def/Swimlane.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/def/Task.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/def/TaskController.hbm.xml"/>

                <mapping resource="org/jbpm/scheduler/def/CreateTimerAction.hbm.xml"/>
                <mapping resource="org/jbpm/scheduler/def/CancelTimerAction.hbm.xml"/>

                <mapping resource="org/jbpm/graph/exe/Comment.hbm.xml"/>
                <mapping resource="org/jbpm/graph/exe/ProcessInstance.hbm.xml"/>
                <mapping resource="org/jbpm/graph/exe/Token.hbm.xml"/>
                <mapping resource="org/jbpm/graph/exe/RuntimeAction.hbm.xml"/>

                <mapping resource="org/jbpm/module/exe/ModuleInstance.hbm.xml"/>

                <mapping resource="org/jbpm/context/exe/ContextInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/TokenVariableMap.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/VariableInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/NullInstance.hbm.xml"/>
                <mapping resource="org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml"/>

                <mapping resource="org/jbpm/job/Job.hbm.xml"/>
                <mapping resource="org/jbpm/job/Timer.hbm.xml"/>
                <mapping resource="org/jbpm/job/ExecuteNodeJob.hbm.xml"/>
                <mapping resource="org/jbpm/job/ExecuteActionJob.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/exe/PooledActor.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml"/>

                <mapping resource="org/jbpm/logging/log/ProcessLog.hbm.xml"/>
                <mapping resource="org/jbpm/logging/log/MessageLog.hbm.xml"/>
                <mapping resource="org/jbpm/logging/log/CompositeLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/ActionLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/NodeLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/ProcessStateLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/SignalLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/TokenCreateLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/TokenEndLog.hbm.xml"/>
                <mapping resource="org/jbpm/graph/log/TransitionLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/VariableLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/VariableCreateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/VariableDeleteLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/VariableUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/log/TaskLog.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml"/>
                <mapping resource="org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml"/>

                <class-cache class="org.jbpm.bytes.ByteArray" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.bytes.ByteArray.byteBlocks" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.context.def.VariableAccess" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.file.def.FileDefinition.processFiles" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.graph.action.Script.variableAccesses" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.graph.def.Action" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.graph.def.Event" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.Event.actions" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.graph.def.ExceptionHandler" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.ExceptionHandler.actions" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.graph.def.Node" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.Node.events" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.Node.exceptionHandlers" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.Node.leavingTransitions" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.Node.arrivingTransitions" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.graph.def.ProcessDefinition" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.ProcessDefinition.events" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.ProcessDefinition.exceptionHandlers" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.ProcessDefinition.nodes" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.ProcessDefinition.actions" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.ProcessDefinition.definitions" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.graph.def.SuperState.nodes" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.graph.def.Transition" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.Transition.events" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.graph.def.Transition.exceptionHandlers" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.graph.node.Decision.decisionConditions" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.graph.node.ProcessState.variableAccesses" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.graph.node.TaskNode.tasks" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.instantiation.Delegation" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.module.def.ModuleDefinition" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.taskmgmt.def.Swimlane.tasks" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.taskmgmt.def.TaskController" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.taskmgmt.def.TaskController.variableAccesses" usage="nonstrict-read-write" />

                <class-cache class="org.jbpm.taskmgmt.def.Task" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.taskmgmt.def.Task.events" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.taskmgmt.def.Task.exceptionHandlers" usage="nonstrict-read-write" />

                <collection-cache collection="org.jbpm.taskmgmt.def.TaskMgmtDefinition.swimlanes" usage="nonstrict-read-write" />
                <collection-cache collection="org.jbpm.taskmgmt.def.TaskMgmtDefinition.tasks" usage="nonstrict-read-write" />
              </session-factory>
            </hibernate-configuration>