It's all about the answers!

Ask a question

Stale data exception in an Operation Participant.


1
1
Sudeshna Mitra (2332831) | asked Aug 17 '12, 1:03 a.m.
edited Aug 18 '12, 1:45 a.m. by David Olsen (5237)
Hi,

I had face an issue with an operation participant.My operation participant
 updates the workitem description,but when I was trying to save the workitem it gives stale data exception.

Here is my operation participant code.
Any help ??

Object data = operation.getOperationData();
    if(data instanceof ISaveParameter) {
        ISaveParameter saveParameter = (ISaveParameter) data;
        IAuditable newState = saveParameter.getNewState();
        if(newState instanceof IAuditable) {
            IWorkItem workItemNewState = (IWorkItem) newState;
            
            IWorkItem workingCopy = (IWorkItem) workItemNewState.getWorkingCopy();
            IWorkItemServer workItemServer = getService(IWorkItemServer.class);
            IAttribute descAttribute =
                    workItemServer.findAttribute(workItemNewState.getProjectArea(), "description", null);
            workingCopy.setValue(descAttribute, "This is description");
            workItemServer.saveWorkItem2(workingCopy, null, null);

Accepted answer


permanent link
Ralph Schoon (63.3k33646) | answered Aug 17 '12, 2:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
As far as I am aware this happens if you try to modify the save parameter directly.

http://www.google.de/search?q=stale+data+participant+site%3Ajazz.net has some hits and I have seen discussions and solutions to this in the forms.

I would suggest to try to fully resolve the new state, get a working copy on that and then save that.

        IWorkItem workitem= (IWorkItem)workItemServer.getAuditableCommon().resolveAuditable(workItemNewState ,IWorkItem.FULL_PROFILE,monitor).getWorkingCopy();

Sudeshna Mitra selected this answer as the correct answer

Comments
Kenery Wang commented Aug 18 '13, 10:06 a.m. | edited Aug 18 '13, 11:03 a.m.

 Hi Ralph,


I wrote the same code as Sudeshna did, and I got the same exception "stale data" so I come here.

Now I've modified my code using the solution you mentioned, but I got another error: java.lang.StackOverflowError

How could I solve it?

Thanks for help.


1
sam detweiler commented Aug 18 '13, 10:46 a.m.

when you do the  workItemServer.saveWorkItem2(workingCopy, null, null);
it will cause another invocation of your extension.  so , you need to use
  workItemServer.saveWorkItem3(workingCopy, null, parameter);
and check the value of parameter to find out if this is a recursive invocation..

google search "saveworkitem3 site:jazz.net" to see examples.


Kenery Wang commented Aug 18 '13, 11:23 a.m. | edited Aug 18 '13, 11:27 a.m.

Hi sam,


Actually I'm not so familiar with developing plugin.
Could u please tell me what parameter I need to set into saveWorkItem3?

All I want to do is just update the value of an attribute within a work item no matter user has modified the attribute or not...

Greatly thanks for your response.

  

One other answer



permanent link
sam detweiler (12.5k6195201) | answered Aug 18 '13, 11:32 a.m.
edited Aug 18 '13, 2:12 p.m.
 you need to set a flag in the data that you can check when you are called a second time (recursion)

The saveWorkItem3() operation takes an additional parameter, a set of strings. This can be used to detect that a subsequent trigger of the participant was caused by this save operation. The following code inserted into the run() operation would allow to detect the recursion 

to save the workitem and pass the parameter

<code>        
additionalParams = new HashSet();  additionalParams.add(IExtensionsDefinitions.UPDATE_PARENT_DURATION_EXTENSION_ID);
 </code>
.
.
.
<code>      
 workItemServer.saveWorkItem3(workingCopy, null, null, additionalParams);
</code>

 to check for the parameter

<code> 
if (saveParameter.getAdditionalSaveParameters().contains(    
     IExtensionsDefinitions.UPDATE_PARENT_DURATION_EXTENSION_ID))
     return;
</code>

Comments
Kenery Wang commented Aug 18 '13, 12:33 p.m. | edited Aug 18 '13, 12:34 p.m.

Thanks for your help, Sam!!


The plugin is just alive!! 

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.