4 Replies Latest reply on Apr 13, 2006 3:28 AM by Konstantin Kolev

    Problem with getVariable

    Sven Sönnichsen Newbie


      I'm having a problem when trying to read a process variable within a taskinstance.

      The variable is set right after process instantiation:

      ProcessInstance processInstance = jbpmContext.loadProcessInstance(processId);
      ContextInstance contextInstance = processInstance.getContextInstance();
      Activity activity = new Activity();
      contextInstance.setVariable("init_arg", activity );

      Here is the code to get the Variable within the TaskInstance:

      ContextInstance contextInstance = taskInstance.getContextInstance();
      Activity activity = (Activity) contextInstance.getVariable("init_arg");

      When I try to read it in a TaskInstance, I get a
      org.jbpm.JbpmException: couldn't deserialize object

      Any ideas or hints?


        • 1. Re: Problem with getVariable
          Hannes Stillerich Newbie


          The variable names are java.lang.String. By default, jBPM supports the following value types:

          * java.lang.String
          * java.lang.Boolean
          * java.lang.Character
          * java.lang.Float
          * java.lang.Double
          * java.lang.Long
          * java.lang.Byte
          * java.lang.Short
          * java.lang.Integer
          * java.util.Date
          * byte[]
          * java.io.Serializable
          * classes that are persistable with hibernate

          I guess your 'Activity' object implents none of that types. Make it serializable.

          • 2. Re: Problem with getVariable
            Sven Sönnichsen Newbie

            Found the solution for my problem:

            My Activity class implemented already Serializable, but... I did not set the serialVersionUID like

            private static final long serialVersionUID = 2175042348064562851L;

            After doing so, getting the variable was not a problem ;-)

            I had also problems with a ClassCastException sometimes, but setting the serialVersionUID seems to sovle this problem as well!


            • 3. Re: Problem with getVariable
              Sven Sönnichsen Newbie

              Well, I was a little bit too quick: the problem is not solved!

              When I cast the object to the correct class (Activity), I sometimes get a

              [list=]org.jbpm.JbpmException: couldn't deserialize object

              Why? Strange enough, that it worked for 2 or 3 times. I've experimented with the serialVersionUID to set it to the default or the a generated value, but I didn't help me.

              Here is the code for Activity (now I used serialVersionUID = 1L):

               * Container for an activity
              public class Activity implements java.io.Serializable {
               private static final long serialVersionUID = 1L;
               public boolean bApproved;
               public String taskId;
               public String processName;
               public String description;
               public String toString() {
               return "[Activity: bApproved=" + bApproved + "]";


              • 4. Re: Problem with getVariable
                Konstantin Kolev Newbie

                Hi, Sven!
                I would suggest you try serializing your Activity first and then set the serialized object through

                contextInstance.setVariable(variableName, serializedValue)

                I don't know if this is convinient approach to you but it worths trying it.