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

    jbpm5 transaction commit

    trh3037

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

         So i debug it ,and find the following problem:

      未命名.jpg

      未命名.jpg

       

      未命名.jpg

       

      Does anyone can solve the problem?

       

      I would be very grateful if you have any suggestions.

       

      Thanks.


        • 1. Re: jbpm5 transaction commit
          trh3037

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

           

          未命名.jpg

          • 2. Re: jbpm5 transaction commit
            d.sizov

            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
              trh3037

              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
                d.sizov

                Can you paste here properties of the Sencond Task?

                • 5. Re: jbpm5 transaction commit
                  trh3037

                     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'

                   

                   

                  未命名.jpg

                   

                   

                   

                  未命名.jpg

                  • 6. Re: jbpm5 transaction commit
                    d.sizov

                    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
                      trh3037

                      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
                        trh3037

                        Does anyone can solve the problem?

                        • 9. Re: jbpm5 transaction commit
                          michael.wagner

                          Hi,

                           

                          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
                            d.sizov

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

                            • 11. Re: jbpm5 transaction commit
                              trh3037

                              here are my codes:

                               

                              private static StatefulKnowledgeSession createKnowledgeSession(
                                                            KnowledgeBase kbase) {
                              
                              
                                                  EntityManagerFactory emf = (EntityManagerFactory) Constants.ctx
                                                                      .getBean("entityManagerFactory");
                                                  Environment env = KnowledgeBaseFactory.newEnvironment();
                                                  env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
                                                  env.set(EnvironmentName.TRANSACTION_MANAGER, Constants.ctx
                                                                      .getBean("txManager"));
                                                  env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
                                                  Properties properties = new Properties();
                                                  properties
                                                                      .put("drools.processInstanceManagerFactory",
                                                                                          "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
                                                  properties.put("drools.processSignalManagerFactory",
                                                                      "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
                                                  KnowledgeSessionConfiguration config = KnowledgeBaseFactory
                                                                      .newKnowledgeSessionConfiguration(properties);
                                                  StatefulKnowledgeSession session = null;
                                                  try {
                                                            session = JPAKnowledgeService.newStatefulKnowledgeSession(kbase,
                                                                                config, env);
                                                            // session = kbase.newStatefulKnowledgeSession(null, env);
                                                  } catch (Exception e) {
                                                            e.printStackTrace();
                                                  }
                                                  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());
                                                            System.out.println(ksession.getProcessInstance(instance.getId()));
                                                  } catch (Throwable t) {
                                                            t.printStackTrace();
                                                  }
                                        }
                              
                              
                              • 12. Re: jbpm5 transaction commit
                                d.sizov

                                Try to use only

                                 

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

                                • 13. Re: jbpm5 transaction commit
                                  michael.wagner

                                  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
                                                  .newKnowledgeBuilder();
                                          kbuilder.add(ResourceFactory.newClassPathResource(processFileName),
                                                  ResourceType.BPMN2);
                                          
                                          
                                          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
                                    trh3037

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

                                     

                                    web.xml

                                     

                                    <listener>
                                                        <listener-class>init.JbpmTaskClientInit</listener-class>
                                              </listener>
                                    
                                    

                                    JbpmTaskClientInit.java

                                    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
                                                                            .getRequiredWebApplicationContext(event.getServletContext());
                                                        
                                                        initTaskService();
                                              }
                                    
                                              private void initTaskService() {
                                    
                                    
                                                        try {
                                    
                                    
                                                                  EntityManagerFactory emfTask = Persistence
                                                                                      .createEntityManagerFactory("org.jbpm.task");
                                                                  // (EntityManagerFactory) Constants.ctx
                                                                  // .getBean("entityManagerFactory");
                                                                  TaskService taskService = new TaskService(emfTask,
                                                                                      SystemEventListenerFactory.getSystemEventListener());
                                                                  /*
                                                                   * 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);
                                                                  thread.start();
                                                                  taskSession.dispose();
                                                                  System.out.println("Server started ...");
                                    
                                    
                                                        } catch (Throwable t) {
                                                                  t.printStackTrace();
                                                        }
                                              }
                                    }
                                    
                                    
                                    
                                    

                                     

                                    applicationContext.xml

                                     

                                    <?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:context="http://www.springframework.org/schema/context"
                                              xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
                                              xsi:schemaLocation="http://www.springframework.org/schema/beans    
                                                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
                                                http://www.springframework.org/schema/context    
                                                http://www.springframework.org/schema/context/spring-context-3.0.xsd    
                                                http://www.springframework.org/schema/tx    
                                                      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
                                              <context:annotation-config />
                                              <bean id="dataSource"
                                                        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                                                        <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>
                                              <bean id="entityManagerFactory"
                                                        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                                                        <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>
                                                        </property>
                                              </bean>
                                    
                                              <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
                                                        <property name="entityManagerFactory" ref="entityManagerFactory" />
                                              </bean>
                                    
                                              <tx:annotation-driven transaction-manager="txManager" />
                                    
                                              <bean
                                                        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
                                              <bean
                                                        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
                                    </beans>
                                    
                                    
                                    1 2 Previous Next