2 Replies Latest reply on Mar 29, 2009 5:42 PM by bradsdavis

    Fetching Task Variable Instances (Early Loading)

    kmajeed

      Can anyone please tell me how to fetch variable instances (early fetching more), currently when i try to fetch it, it makes around 4-5 sql calls which makes my task/inbox/WIP very slow - can anyone please suggest me a suitable approach for this. I am storing my task data in a serializable form.

        • 1. Re: Fetching Task Variable Instances (Early Loading)
          kukeltje

          I personally never displayed taskvariables in my tasklist. I display the businesskey, which is in most cases enough and if I need more info, I runtime gave the task description a sensible value and display that.

          • 2. Re: Fetching Task Variable Instances (Early Loading)
            bradsdavis

            Yeah, my suggestion here is the following.

            First, I dont think this is as efficient as it should be. However, this is my suggestion at the most efficient result.

            Create a DTO that includes the values you want in the grid. Then do a HQL query to fetch the task instance. The key is to make the variable local to the task instance so that it can be pulled in a eager fashion.

            So, when you create your task, just add a controller that copies the value from the process instance to the task. That is equivalent to creating a variable locally on the task instance.

            So, then you need to fetch the variable eagerly.

            "select task from org.jbpm.taskmgmt.exe.TaskInstance task fetch all properties left join fetch task.variableInstances varInstance"
            


            When you are populating your DTO from your TaskInstance objects gathered in the HQL query, make sure you say "getVariableLocally("variableName") rather than the getVariable method. That is crucial.