Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Stale data exception in an Operation Participant.

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);

1

1 vote


Accepted answer

Permanent link
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

2 votes

Comments

 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.

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.

1 vote

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
 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>

3 votes

Comments

Thanks for your help, Sam!!


The plugin is just alive!! 

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 383
× 369

Question asked: Aug 17 '12, 1:03 a.m.

Question was seen: 7,501 times

Last updated: Aug 18 '13, 5:55 p.m.

Confirmation Cancel Confirm