1 2 Previous Next 29 Replies Latest reply on Nov 14, 2012 4:18 PM by Juliano Dantas

    jbpm5 transaction commit

    RuiHua Tang Newbie

          I start the process ,but it can not start the second 'user Task'.

         So i debug it ,and find the following problem:






      Does anyone can solve the problem?


      I would be very grateful if you have any suggestions.



        • 1. Re: jbpm5 transaction commit
          RuiHua Tang Newbie

          When I initiated the following process, it running normally , and also finish the process instance.



          • 2. Re: jbpm5 transaction commit
            Dmitry Sizov Newbie

            When you complete the first task, the second task will be started automatically. Try to use gateway, if you want start 2 tasks simultaneously.

            • 3. Re: jbpm5 transaction commit
              RuiHua Tang Newbie

              Sorry, I did not express clearly.

              My problem is when I finish the first task, the second task does not start automatically


              • 4. Re: jbpm5 transaction commit
                Dmitry Sizov Newbie

                Can you paste here properties of the Sencond Task?

                • 5. Re: jbpm5 transaction commit
                  RuiHua Tang Newbie

                     Sure,here are the two task's pictures,


                     But i don't think that the reason is  the task's configuration.


                     Because when I started the process, it has been wrong ,the processInstance has lost the 'kruntime' and the 'process'








                  • 6. Re: jbpm5 transaction commit
                    Dmitry Sizov Newbie

                    Is user of the Second Task the same as user of the First Task?

                    P.S. as I known processinstance may be out of sinc of Knowledge Session, after you get it (kSession.getProcessInstance())

                    • 7. Re: jbpm5 transaction commit
                      RuiHua Tang Newbie

                      I set the tasks with the same user,but it is still wrong, even if I use different user


                      I get the processInstance  by it (kSession.getProcessInstance()) ,but the processInstance still lost two of its properties.


                      It leads to even if I completed the first task, the second task won't be initiated automatically

                      • 8. Re: jbpm5 transaction commit
                        RuiHua Tang Newbie

                        Does anyone can solve the problem?

                        • 9. Re: jbpm5 transaction commit
                          Michael Wagner Newbie



                          I see you are lost as I am with my database problems. Nobody answering. If you want to, you can post your code. I can try it out for you on my side.


                          Regards M.

                          • 10. Re: jbpm5 transaction commit
                            Dmitry Sizov Newbie

                            How are you  get KnowledgeSession? If you using JPA you must use CommandBasedWSHumantaskHandler instead WSHumanTaskHandler

                            • 11. Re: jbpm5 transaction commit
                              RuiHua Tang Newbie

                              here are my codes:


                              private static StatefulKnowledgeSession createKnowledgeSession(
                                                            KnowledgeBase kbase) {
                                                  EntityManagerFactory emf = (EntityManagerFactory) Constants.ctx
                                                  Environment env = KnowledgeBaseFactory.newEnvironment();
                                                  env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
                                                  env.set(EnvironmentName.TRANSACTION_MANAGER, Constants.ctx
                                                  env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
                                                  Properties properties = new Properties();
                                                  KnowledgeSessionConfiguration config = KnowledgeBaseFactory
                                                  StatefulKnowledgeSession session = null;
                                                  try {
                                                            session = JPAKnowledgeService.newStatefulKnowledgeSession(kbase,
                                                                                config, env);
                                                            // session = kbase.newStatefulKnowledgeSession(null, env);
                                                  } catch (Exception e) {
                                                  return session;
                              public void onTest1(Event event) throws InterruptedException {
                                                  try {
                                                            ksession = JbpmAPIUtil.createKnowledgeSession("HelloProcess.bpmn");
                                                            logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(
                                                                                ksession, "testlog", 1000);
                                                            ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
                                                                                new CommandBasedWSHumanTaskHandler(ksession));
                                                            dblogger = new JPAWorkingMemoryDbLogger(ksession);
                                                            Map<String, Object> params = new HashMap<String, Object>();
                                                            params.put("employee", "krisv");
                                                            instance = ksession.startProcess("HelloProcess");
                                                            System.out.println(instance.getId() + "************************"
                                                                                + instance.getState());
                                                  } catch (Throwable t) {
                              • 12. Re: jbpm5 transaction commit
                                Dmitry Sizov Newbie

                                Try to use only


                                Environment env = KnowledgeBaseFactory.newEnvironment();
                                env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

                                • 13. Re: jbpm5 transaction commit
                                  Michael Wagner Newbie

                                  Thanks for sharing. Want to try it out, but I do not know how to resolve "Constants.ctx". Could you please paste your imports, too?


                                  Good idea with this api util. Mine lookes like this:


                                  public class JbpmAPIUtil {
                                      public static StatefulKnowledgeSession createKnowledgeSession(String processFileName,
                                              ResourceType resourceType) throws Exception {
                                          KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
                                          KnowledgeBase kbase = kbuilder.newKnowledgeBase();
                                          StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
                                          KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
                                          return ksession;
                                      public static StatefulKnowledgeSession createKnowledgeSession(String processFileName)
                                              throws Exception {
                                          return createKnowledgeSession(processFileName, ResourceType.BPMN2);
                                  • 14. Re: jbpm5 transaction commit
                                    RuiHua Tang Newbie

                                    Yes of course, i use spring to manage transaction for jbpm5 :






                                    package init;
                                    import javax.persistence.EntityManagerFactory;
                                    import javax.persistence.Persistence;
                                    import javax.persistence.PersistenceUnit;
                                    import javax.servlet.ServletContextEvent;
                                    import javax.servlet.ServletContextListener;
                                    import org.drools.SystemEventListenerFactory;
                                    import org.jbpm.task.Group;
                                    import org.jbpm.task.User;
                                    import org.jbpm.task.service.TaskService;
                                    import org.jbpm.task.service.TaskServiceSession;
                                    import org.jbpm.task.service.mina.MinaTaskServer;
                                    import org.springframework.web.context.support.WebApplicationContextUtils;
                                    import util.Constants;
                                    public class JbpmTaskClientInit implements ServletContextListener {
                                              public void contextDestroyed(ServletContextEvent arg0) {
                                                        // TODO Auto-generated method stub
                                              public void contextInitialized(ServletContextEvent event) {
                                                        Constants.ctx = WebApplicationContextUtils
                                              private void initTaskService() {
                                                        try {
                                                                  EntityManagerFactory emfTask = Persistence
                                                                  // (EntityManagerFactory) Constants.ctx
                                                                  // .getBean("entityManagerFactory");
                                                                  TaskService taskService = new TaskService(emfTask,
                                                                   * Add the required users
                                                                  TaskServiceSession taskSession = taskService.createSession();
                                                                  taskSession.addUser(new User("Administrator"));
                                                                  taskSession.addUser(new User("tangrh"));
                                                                  taskSession.addUser(new User("krisv"));
                                                                  taskSession.addUser(new User("john"));
                                                                  taskSession.addUser(new User("mary"));
                                                                  taskSession.addGroup(new Group("PM"));
                                                                  /* Start Mina server for HT */
                                                                  MinaTaskServer server = new MinaTaskServer(taskService);
                                                                  Thread thread = new Thread(server);
                                                                  System.out.println("Server started ...");
                                                        } catch (Throwable t) {




                                    <?xml version="1.0" encoding="UTF-8"?>
                                    <beans xmlns="http://www.springframework.org/schema/beans"
                                              xmlns:drools="http://drools.org/schema/drools-spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                              xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
                                              <context:annotation-config />
                                              <bean id="dataSource"
                                                        <property name="driverClassName" value="oracle.jdbc.OracleDriver" />
                                                        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
                                                        <property name="username" value="jbpm" />
                                                        <property name="password" value="jbpm" />
                                              <bean id="entityManagerFactory"
                                                        <property name="persistenceUnitName" value="org.jbpm.persistence.jpa"></property>
                                                        <property name="dataSource" ref="dataSource"></property>
                                                        <property name="jpaVendorAdapter">
                                                                  <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                                                                            <property name="database" value="ORACLE" />
                                                                            <property name="showSql" value="true" />
                                              <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                                                        <property name="entityManagerFactory" ref="entityManagerFactory" />
                                              <tx:annotation-driven transaction-manager="txManager" />
                                                        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
                                                        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
                                    1 2 Previous Next