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