3 Replies Latest reply on Apr 29, 2011 1:47 AM by harishpandya

    jbpmContext.getSessionFactory().openSession() and jbpmConte

    rainhust

       

      Session session = jbpmContext.getSessionFactory().openSession();
      Transaction tx = session.beginTransaction();
      

      this's ok!

      and i use following code , will get a "Transaction not successfully started" exception.

      Session session = jbpmContext.getSession();
      Transaction tx = session.beginTransaction();
      


      i saw the source code, and in "org.jbpm.persistence.db.DbPersistenceService" class i found:

       public Session getSession() {
       if ( (session==null)
       && (getSessionFactory()!=null)
       ) {
       Connection connection = getConnection(false);
       if (isCurrentSessionEnabled) {
       session = getSessionFactory().getCurrentSession();
       log.debug("using current hibernate session " + session);
       mustSessionBeClosed = false;
       mustSessionBeFlushed = false;
       mustConnectionBeClosed = false;
       } else if (connection!=null) {
       log.debug("creating hibernate session with connection "+connection);
       session = getSessionFactory().openSession(connection);
       mustSessionBeClosed = true;
       mustSessionBeFlushed = true;
       mustConnectionBeClosed = false;
       } else {
       log.debug("creating hibernate session");
       session = getSessionFactory().openSession();
       mustSessionBeClosed = true;
       mustSessionBeFlushed = true;
       mustConnectionBeClosed = false;
       }
      
       if (isTransactionEnabled) {
       beginTransaction();
       }
       }
       return session;
       }


      maybe "isTransactionEnabled" started a transaction,and this cause the exception.

      so ,i want to know where "isTransactionEnabled" can config in jbpm config file.

      also you can tell me jbpmContext.getSessionFactory().openSession() and jbpmContext.getSession() difference, and how to correct using them.

      any advice, thx.

        • 1. Re:  jbpmContext.getSessionFactory().openSession() and jbpmC
          anuragpaliwal

          Hi,

          http://docs.jboss.com/jbpm/v3/userguide/persistence.html#thedbpersistenceservicefactory

          Go through this documentation. I hope it will answer all your queries.

          • 2. Re:  jbpmContext.getSessionFactory().openSession() and jbpmC
            rainhust

            thanks, there is a lot explanation.

            • 3. jbpmContext.getSessionFactory().openSession() and jbpmConte
              harishpandya

              Hi Anurag,

               

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

              So i changed the

               

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

               

              property of jbpm.cfg.xml 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>