1 Reply Latest reply on Sep 20, 2013 12:15 PM by Maciej Swiderski

    JBPM 5 Transaction in EJB 3

    swienty1 Newbie

      Hello,

       

      I'm using JBpm 5.4 with JBoss 7.1 and JBPM 5.4. I have problem with transaction when I create kssesion object inside EJB (transaction managed by container). I don't know how to force (configure) JBPM 5 to share the same transaction with EJB. From my tests, it looks like JBPM 5 creates own transaction (create new transaction, and not use current transaction from ejb context).

       

      My configuration of JBPM looks like:

       

       

      @PersistenceUnit(unitName = "org.jbpm.persistence.jpa")
      private EntityManagerFactory emf;
      
      ...
      StatefulKnowledgeSession ksession = null;
      KnowledgeBase kbase = null;
      
      Environment env = KnowledgeBaseFactory.newEnvironment();
      env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
      env.set(EnvironmentName.TRANSACTION_MANAGER, new ContainerManagedTransactionManager());
      env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, new JpaProcessPersistenceContextManager(env));
      KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
      ...
      kbase = kbuilder.newKnowledgeBase();
      ksession =    JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
      
      

       

      persistence.xml

       

      <persistence-unit name="org.jbpm.persistence.jpa"
              transaction-type="JTA">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <jta-data-source>java:/DefaultDS</jta-data-source>
              <mapping-file>META-INF/JBPMorm-JPA2.xml</mapping-file>
              <mapping-file>META-INF/ProcessInstanceInfoMapping-JPA2.xml</mapping-file>
      
              <class>org.drools.persistence.info.SessionInfo</class>
              <class>org.drools.persistence.info.WorkItemInfo</class>
              <class>org.jbpm.process.audit.ProcessInstanceLog</class>
              <class>org.jbpm.process.audit.NodeInstanceLog</class>
              <class>org.jbpm.process.audit.VariableInstanceLog</class>
      
              <properties>
                  <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
                  <property name="hibernate.max_fetch_depth" value="3" />
                  <property name="hibernate.hbm2ddl.auto" value="update" />
                  <property name="hibernate.show_sql" value="true" />
                  <property name="hibernate.transaction.manager_lookup_class"
                           value="org.hibernate.transaction.JBossTransactionManagerLookup" />
      <!--
                   BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem
                      to cause problems -->
                  <property name="hibernate.id.new_generator_mappings" value="false" />
              </properties>
      
          </persistence-unit>
      
      

       

      If someone know answer, please help.