0 Replies Latest reply on Nov 24, 2008 4:29 PM by trouby

    JBPM and Managed Container Transactions

    trouby

      Hey,
      I am trying to make JBPM to work smoothly through EJB3 components with no success,

      After invoking very simple methods through a stateless EJB3 such as:

      ProcessInstance pi = jbpmContext.loadProcessInstance(spmlTask.getWorkflowProcessId());
      



      I'm getting errors such as:
      23:13:38,858 ERROR [TimerImpl] Error invoking ejbTimeout: javax.ejb.EJBException: javax.persistence.TransactionRequiredException: Entity
      Manager must be access within a transaction
      



      I assumed this is due to the fact that somewhere JBPM commits the transaction so invocations after that causes the exception,

      I have followed section "7.1.3. Managed transactions" in the manual:

      A stateless session facade in front of jBPM is a good practice. The easiest way on how to bind the jbpm transaction to the container transaction is to make sure that the hibernate configuration used by jbpm refers to an xa-datasource. So jbpm will have its own hibernate session, there will only be 1 jdbc connection and 1 transaction.


      But setting it up is not clear enough, I tried to configure JBPM as follows:


      hibernate.cfg.xml
      ...
      
      <property name="connection.datasource">java:/veloDatasource</property>
       <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
       <property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
      
      ...
      



      jbpm.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" />
      
      ...
      




      where veloDataSource is defined in persistence.xml as follows
      <local-tx-datasource>
       <jndi-name>veloDatasource</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/velo</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>root</user-name>
       <password>password</password>
       </local-tx-datasource>
      




      Seems like JBPM is not using the MC transaction and if I understand correctly, JBPM commits the transaction and that what causes the persistence unit to fail later on.,



      Can anyone give me a hand how to proceed from here?



      Man thanks,


      Asaf.