4 Replies Latest reply on Jul 25, 2012 7:54 PM by binglim

    How do you implement data persistence in jbpm5 and simulate multiple trials in between nodes?

    binglim Newbie

      1) How do you implement data persistence in jbpm5?

      I've tried using hibernate and examples from https://community.jboss.org/people/bpmn2user/blog/2011/02/27/helloprocess-example-using-jbpm5-eclipse-plug-in

      However, the example is in jbpm5 and it's not working on my local workspace where I am using jbpm 5.3.

      (Is there a straight-forward way in implementing persistence?)

       

      2) In jbpm4, it allows simple loop-like cycle in between nodes (simulating multiple tries before cancelling the task), similar to the attached image.
          Instead of using multiple boundary event nodes and diverging/converging gateways, is there a similar node/function in jbpm5 that functions like the state node shown below?

         

      MultipleTrialsExample.JPG

       

      I've been trying to figure these out for weeks but to no avail. I hope to get some advice in resolving these issues.

      Any help is appreciated. Thanks!

        • 1. Re: How do you implement data persistence in jbpm5 and simulate multiple trials in between nodes?
          Mauricio Salatino Master

          Hi,

          1) did you check out the documentation? what are you trying to achieve with persistence? if you have a long running process, the documentation should help you to get things set up.

          Are you using maven? can you share what's the problem in your project? what do you mean with is not working?

           

          2) You have different options:

          a) Do you really need to draw your retrying mechanisms? Is it relevant for the business? or is just a technical detail?

          If it's a technical concern, you should probably better not draw it in the process file and delegate that logic to the work item hanlder that is in charge of that interaction.

           

          b) you can model it in the diagram using gateways

           

          Cheers

          • 2. Re: How do you implement data persistence in jbpm5 and simulate multiple trials in between nodes?
            binglim Newbie

            Thanks a lot for the reply.

             

            1) Below is the error message I get from running the example:

             

              23/07 14:25:55,418[main] ERROR hibernate.impl.SessionFactoryImpl.<init>  - Error in named query: ProcessInstancesWaitingForEvent

            org.hibernate.hql.ast.QuerySyntaxException: ProcessInstanceInfo is not mapped [select processInstanceInfo.processInstanceId from ProcessInstanceInfo processInstanceInfo where :type in elements(processInstanceInfo.eventTypes)]

                      at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)

                      at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)

                      at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:94)

                      at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:316)

                      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3228)

                      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3112)

                      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:720)

                      at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:571)

                      at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288)

                      at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231)

                      at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)

                      at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)

                      at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)

                      at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)

                      at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)

                      at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)

                      at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:484)

                      at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:394)

                      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)

                      at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)

                      at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)

                      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)

                      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)

                      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:34)

                      at com.sample.HelloProcessTest.main(HelloProcessTest.java:43)

            javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.task] Unable to build EntityManagerFactory

             

             

            Aside from this example, is there an easier way to implement database persistence?

             

            2) I am designing a worklow process that simulates writing a file to an archive and it is relevant for business, so it would be better if it is easy to understand.

                When the task exceeds a certain time limit, it will enter a human task to prompt the user if he would like to retry or cancel the task, therefore requires the looping.

                Is there a specific node that can implement that function? 

             

            3) Is it possible to get ksession from an external process without passing in the StatefulKnowledgeBaseSession as a parameter?
                To do signaling from an external source, I need to execute

            ksession.signalEvent(type, eventData);

                But I do not want the external process to know the ksession directly by passing it in as a parameter. So is it possible to obtain the ksession from WorkItem or WorkItemManager?

            • 3. Re: How do you implement data persistence in jbpm5 and simulate multiple trials in between nodes?
              Mauricio Salatino Master

              Hi Bing,

              1) you don't need to implement persistence, you just need to configure it to work in your environment. if you take a look at the error that you paste here, you will notice that is a JPA error, not a jBPM error.

              So you need to check your persistence.xml file and the persistence unit defined inside it. But this is a java question, not specific to jBPM. The error in this case is saying that you have a JPQL (JPA query) which uses the ProcessInstanceInfo and you don't have that entity defined as an entity inside the persistence unit configuration.

              2) So, as far as I understand you want to execute an automatic activity, which is writing a file and then a human task to control that right? Then the loop can be implemented with a ServiceTask + a HUman task and the required gateways to draw the loop.

               

              3) If you are using persistent session, you should pass the persisted session ID in order to restore your session and then be able to signal an event. Notice that the event is being signaled at session level, which means that you can do much more things that just signaling a specific process instance.

               

              Cheers

              • 4. Re: How do you implement data persistence in jbpm5 and simulate multiple trials in between nodes?
                binglim Newbie

                Hi Mauricio,


                Thanks a lot for the reply.

                 

                1) However, I do not know how to configure a persistence.xml to enable persistence in my environment. Is there a detailed and simple to understand example that I can use as a reference?

                 

                2) I used gateways to draw the workflow but it's too messy and confusing. Is there a node that can handle the looping and make it look neater, just like in JBPM4?

                 

                workflow.JPG

                 

                I have attached the whole zip file if you need any other information.

                Thank you for your time and assistance!

                 

                Best,

                Bing