3 Replies Latest reply on Nov 11, 2010 6:09 PM by melossi

    Storing java.util.Collection on process

    rubenbentein

      I have a question about a best practise concerning processes with a dynamic list as a variable.

       

      Let's say for example i have an process which has to store 0..* objects as variables. I.e. an process B

       

      public class B{

           string b1;

           string b2;

           java.util.Collection<A> aCollection;

      }

       

      and a class A


      public class A{

           string a1;

           string a2;

      }

       


      so before calling

       

      executionService.startProcessInstanceByKey("B-process-name", variables);

       

      I have to fill the variables map. But how should i add aCollection ? Should i do something like


      variables.put("b1", someBObject.b1);

      variables.put("b2", someBObject.b2);

      for (int i=0 ; i<someBObject.aCollection.size() ; i++){

           variables.put("aCollection[" + i + "].a1", aCollection.get(i).a1);

           variables.put("aCollection[" + i + "].a2", aCollection.get(i).a2);

      }

       

      Or maybe there is a better/cleaner solution.

      Or should i store these object in my own tables, and just store a reference (id) on the variables list ?

       

      Thanks for any replies

        • 1. Re: Storing java.util.Collection on process
          melossi

          I have a  dynamic form with a grid with 3 columns, as I variables to store the  values of each cell and then retrieve them for display in a report?

          • 2. Re: Storing java.util.Collection on process
            aguizar

            If your collection class and all its elements are Serializable, you have the option to set the whole aCollection as a variable, or even the parent someBObject, again, if class B is Serializable. This is convenient, but if you don't want your objects stored as binaries, you can provide a Hibernate mapping for class B, add it to the jbpm.hibernate.cfg.xml file, and simply set someBObject as variable. jBPM will recognize Hibernatable objects with either Long or String identifiers and persist them by storing their ID value automatically. Hope this helps.

            • 3. Re: Storing java.util.Collection on process
              melossi

              I would appreciate if you give me an example of how to use variables serializable classes