2 Replies Latest reply on Jun 16, 2007 6:09 PM by Claudio Grasso

    Business process variables duplicted when updated.

    Claudio Grasso Newbie

      Hi all!
      I am trying to update JBPM business process variables using Seam annotations.
      I noticed the following behavior:

      When I use:
      @In
      @Out
      private String unDato;

      my class retrieves the variable but the modifications do not get persisted when I call the @EndTask annotated function (the last one before destroying the class)

      When I use:
      @In
      @Out(scope=ScopeType.BUSINESS_PROCESS, required=false)
      private String unDato;

      my class also retrieves the variables but as soon as the class gets created a new variable with the same name (unDato) and value is created in the database (jbpm_variableinstance). When I leave the class and finish the task, The old variable is updated correctly but the new "ghost" variable remains in the DB (with the original value).

      I found a workaround by updating variables "by hand": instead of using @Out I use:

      Contexts.getBusinessProcessContext().set("unDato", unDato);

      This way I do what I need: just modify the content of the original value.

      Im I doing something wrong in the way I am trying to use annotations?

      Thanks in advance,

      Claudio


        • 1. Re: Business process variables duplicted when updated.
          Gavin King Master

          That is all totally expected behavior.

          A String doesn't have an implicit BUSINESS_PROCESS scope, you need to specify that explicitly.

          And Seam tasks are atomic - they do not modify the process instance variables until the task completes successfully, at which time the task instance variables are copied back to the process instance. This is a Really Nice Thing.

          • 2. Re: Business process variables duplicted when updated.
            Claudio Grasso Newbie

            Thank you Gavin for your PROMPT (yes in capitals :-) ) response.

            I would like to verify if I am interpreting the right way what´s going on. Here is a snippet from my code:

            @Stateful
            @Name("verifyData")
            public class verificarDatosBean implements verificarDatos {

            @In
            @Out(scope=ScopeType.BUSINESS_PROCESS, required=false)

            @EndTask
            public String saveModifiedData() {
            return "/home.seam";
            }

            @Remove @Destroy public void destroy(){}

            public String getUnDato() {
            return unDato;
            }

            public void setUnDato(String unDato) {
            this.unDato = unDato;
            }

            }

            1. When seam finds:

            @In
            private String unDato;

            injects the the BUSSINESS_PROCESS variable unDato. (The variable was already created elsewere with BUSSINESS_PROCESS scope AND I already called a method annotated with @StartTask, so I am inside a BUSSINESS_PROCESS)

            2. As soon as any method inside the object is executed (I think in my case it is the getter because this EJB is acting as a Backing Bean) Seams finds:

            private String unDato;
            @Out(scope=ScopeType.BUSINESS_PROCESS, required=false)

            and creates the new variable with the same name (unDato) and scope (unDato) but with different Id.

            3. When I execute:

            @EndTask
            public String saveModifiedData()

            Seam sees that the task is completed and updates the original variable.

            Forgive my verbosity but I want to be sure I am conceptually right. (So I learn once for good)

            Claudio