2 Replies Latest reply on Dec 8, 2008 8:51 PM by Ronald van Kuijk

    Transaction Question: @In JbpmContext ... no Transation

    walter mauritz Newbie

      i inject a jbpmContext. then i retrieve a hibernate session from it.


      @Name("todoList")
      public class TodoList {
      ...
      @In JbpmContext jbpmContext;
      @In Session jbpmSession jbpmSession;
      ...
      
      @Transactional
      public void do() {
      jbpmContext.getSession(); //FIXME: has NO Transaction
      jbpmSession //!!! Transaction OK
      ...



      Question:
      why does the jbpmContext-session has NO Transaction enabled?
      How can I get a transaction-enabled JbpmContext?


      Note: I use two datasources with JTA XA


      If I use @In Session from both sessionfactories, Transaction works as expected.


      components.xml:


      <persistence:hibernate-session-factory name="jbpmSessionFactory" 
         auto-create="true" cfg-resource-name="jbpm-hibernate.cfg.xml"/>
      <persistence:managed-hibernate-session name="jbpmSession" 
         auto-create="true" session-factory-jndi-name="java:/jbpmSessionFactory"/>
                        
      <persistence:hibernate-session-factory name="appSessionFactory" 
         auto-create="true" cfg-resource-name="app-hibernate.cfg.xml"/>
      <persistence:managed-hibernate-session name="appSession" 
         auto-create="true" session-factory-jndi-name="java:/appSessionFactory"/>



      jbpm-hibernate.cfg.xml:


      <hibernate-configuration>
        <session-factory name="java:/jbpmSessionFactory">
          <property name="transaction.flush_before_completion">true</property>
          <property name="connection.release_mode">after_statement</property>
          <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
          <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
          <property name="show_sql">true</property>
          <property name="connection.datasource">java:/jbpmDatasource</property>
          <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
          <property name="hbm2ddl.auto">validate</property>
      ...



      jbpm-datasource:


      <datasources>
         <xa-datasource>
           <jndi-name>jbpmDatasource</jndi-name>
           <track-connection-by-tx/>
           <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
           <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
           <xa-datasource-property name="PortNumber">5432</xa-datasource-property>
           <xa-datasource-property name="DatabaseName">jbpm</xa-datasource-property>
           <xa-datasource-property name="User">postgres</xa-datasource-property>
           <xa-datasource-property name="Password">postgres</xa-datasource-property> 
         </xa-datasource>
      </datasources>



      app-datasource:


      <datasources>
         <xa-datasource>
           <jndi-name>employeeDatasource</jndi-name>
           <track-connection-by-tx/>
           <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
           <xa-datasource-property name="ServerName">localhost</xa-datasource-property>
           <xa-datasource-property name="PortNumber">5432</xa-datasource-property>
           <xa-datasource-property name="DatabaseName">templtest</xa-datasource-property>
           <xa-datasource-property name="User">postgres</xa-datasource-property>
           <xa-datasource-property name="Password">postgres</xa-datasource-property> 
         </xa-datasource>
      </datasources>



      seam 2.1.1 CR1
      jboss as 4.2.3GA

        • 1. Re: Transaction Question: @In JbpmContext ... no Transation
          walter mauritz Newbie

          app-hibernate.cfg.xml


          <hibernate-configuration>
            <session-factory name="java:/appSessionFactory">
              <property name="transaction.flush_before_completion">true</property>
              <property name="connection.release_mode">after_statement</property>
              <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
              <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
              <property name="show_sql">true</property>
              <property name="connection.datasource">java:/employeeDatasource</property>
              <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
              <property name="hbm2ddl.auto">validate</property>
              
              <mapping class="at.iqsoft.templtest.model.TplHaustier"/>
          ...




          jbpm.cfg.xml


          <jbpm-configuration>
          <string name='resource.hibernate.cfg.xml' value='jbpm-hibernate.cfg.xml' />
            <jbpm-context>
              <service name="persistence">
                 <factory>
                    <bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
                       <field name="isTransactionEnabled"><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="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
              <service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
            </jbpm-context>
          </jbpm-configuration>



          btw. thx to you for great SEAM docs. very useful.

          • 2. Re: Transaction Question: @In JbpmContext ... no Transation
            Ronald van Kuijk Apprentice

            Warning: I've not done anything like this yet, so I might be completely wrong...


            In jbpm.cfg.xml you say  isTransactionEnabled=false. This makes sure jBPM does not handle transactions but relies on the container. If you want to have the session in your context, I think it is not automatically injected in the contest. Something like jBPMContext.setSession(jbpmSession) does the job. So afaik, the behaviour you see is not 'wrong'