4 Replies Latest reply on Oct 4, 2005 1:15 PM by llucifer

    jBPM Persistent Transaction Management

    marcus.junk

      Hi,

      We are using jBPM 3.0 embedded in a J2EE app running within JBoss.

      We have transaction management at the EJB level and wish to implement the following scenario for all usage of jBPM within our EJB's.

      EJB
      ----
      1. start j2ee app transaction

      2. start jBPM Process Instance
      2.1 as a result of BP flow modify some j2ee app data

      3.commit j2ee app transaction
      ----


      We want atomic transactions with both the j2ee app specific data and the jBPM specific data. So that when we commit the j2ee app transaction the jBPM specific data modifications are also committed at this point.

      How do we get jBPM to hook into the transaction being managed by the current EJB managing thread?

      It seems to do anything jBPM specific to the jBPM database that I need to create a jBPM session.

      Does anyone have ideas or comments on how they have solved similar issues with transactions and J2EE usage with jBPM 3.0 ??

      Thanks in advance, Marcus.



        • 1. Re: jBPM Persistent Transaction Management
          marcus.junk

          Solution / Advice :

          JBPM is able to support the scenario I described above, or more to the point I think it is actually hibernate that supports this transaction management, which could explain why I recieved no responses to this problem.

          In short to solve the problem I did the following.

          Modified the hibernate.properties to talk to a data source and to use JTA Transaction management.


          hibernate.jndi.class=org.jboss.naming.NamingContextFactory
          hibernate.connection.datasource=java:comp/env/jdbc/XXXDB
          hibernate.transaction.factory_class = net.sf.hibernate.transaction.JTATransactionFactory


          Then using JTA transaction management I simply set up my EJB to provide a transaction for my calling method and this provided the required transaction functionality across both my ejb data source and the JBPM data source.

          hope this helps those with the same problem or question about JBPM's transaction ability within JBoss.

          M.



          • 2. Re: jBPM Persistent Transaction Management
            marcus.junk

            My previous post was not complete.

            we also needed to add the following properties to the hibernate.properties file.


            hibernate.transaction.flush_before_completion=true
            hibernate.connection.release_mode=after_statement
            hibernate.transaction.auto_close_session=true


            And finally the most crucial point was that at the end of the EJB method that owns the transaction we needed to explicitly call flush on the underlying hibernate session as the code snippet below illustrates. If I didn't explicity call the flush on the hibernate session then I got my business process saved in a mid process state, even thou the business process should have completed immediately as I knew actually happened thru remote debug sessions.

            /**
            
             * @throws Exception
            
             *
            
             * @ejb.interface-method
            
             * @ejb.transaction
            
             * type="Required"
            
             */
            
             public void testBusinessProcess() throws Exception {
            
            
            
            
             // need to hook into current singleton jbpmSessionFactory using JNDI
            
             JbpmSessionFactory jbpmSessionFactory =
            
             (JbpmSessionFactory) new JndiContext().lookup("java:/jbpm/JbpmSessionFactory", JbpmSessionFactory.class);
            
            
            
             JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
            
            
            
             try {
            
             ProcessDefinition processDefinition = jbpmSession.getGraphSession().findLatestProcessDefinition(bpName);
            
            
            
            jbpmSession.getGraphSession().findProcessInstances(processDefinition.getId());
            
             ProcessInstance processInstance = new ProcessInstance(processDefinition);
            
             processInstance.signal();
            
            
             jbpmSession.getGraphSession().saveProcessInstance(processInstance);
            
            
            
             jbpmSession.getSession().flush();
            
             } finally {
            
             jbpmSession.close();
            
             }
            
             }
            


            excuse the nasty code formatting above but thats as best I could do after copy and pasting into this forum editor.

            M.

            • 3. Re: jBPM Persistent Transaction Management
              russelldb

              Many thanks for posting your solution. You have helped me enormously.

              Regards

              Russell

              • 4. Re: jBPM Persistent Transaction Management
                llucifer

                Markus, how do you deploy jbpm? Do you include the libraries in your ear or do you deploy jpbm as a .sar?