MultiStaleDataException when saving the work item
Hi,
Im getting MultiStaleDataException when saving the work item. The exception occurs after I tried to set attribute and save the work item couple times. Following is the code how I set the attribute and save the work item. Any idea what may cause the exception? What did I do wrong in the code? Please help. Thanks.
Any help is appreciated. Thank you very much.
IWorkItemClient wiClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager wcManager = wiClient.getWorkItemWorkingCopyManager();
IWorkItemHandle handle = (IWorkItemHandle)workitem.getItemHandle();
ItemProfile<IWorkItem> profile = IWorkItem.FULL_PROFILE;
wcManager.connect(handle, profile, monitor);
WorkItemWorkingCopy workingCopy = wcManager.getWorkingCopy(handle);
IWorkItem wi = workingCopy.getWorkItem();
wi.setValue(attr, attrValue); (**note: attr is IAttribute and attrValue is Object)
IDetailedStatus s = workingCopy.save(monitor);
Exception: com.ibm.team.workitem.common.model.MultiStaleDataException: Stale Data
Message: Exception saving work item
Details: Exception saving work item
com.ibm.team.workitem.common.model.MultiStaleDataException: Stale Data
at com.ibm.team.workitem.common.internal.util.Utils.checkSaveResult(Utils.java:272)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.saveWorkItems(WorkItemWorkingCopyRegistry.java:1642)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.saveAffected(WorkItemWorkingCopyRegistry.java:1538)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.save(WorkItemWorkingCopyRegistry.java:1439)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.save(WorkItemWorkingCopyRegistry.java:1410)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.save(WorkItemWorkingCopyManager.java:115)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyImpl.save(WorkItemWorkingCopyImpl.java:221)
Im getting MultiStaleDataException when saving the work item. The exception occurs after I tried to set attribute and save the work item couple times. Following is the code how I set the attribute and save the work item. Any idea what may cause the exception? What did I do wrong in the code? Please help. Thanks.
Any help is appreciated. Thank you very much.
IWorkItemClient wiClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItemWorkingCopyManager wcManager = wiClient.getWorkItemWorkingCopyManager();
IWorkItemHandle handle = (IWorkItemHandle)workitem.getItemHandle();
ItemProfile<IWorkItem> profile = IWorkItem.FULL_PROFILE;
wcManager.connect(handle, profile, monitor);
WorkItemWorkingCopy workingCopy = wcManager.getWorkingCopy(handle);
IWorkItem wi = workingCopy.getWorkItem();
wi.setValue(attr, attrValue); (**note: attr is IAttribute and attrValue is Object)
IDetailedStatus s = workingCopy.save(monitor);
Exception: com.ibm.team.workitem.common.model.MultiStaleDataException: Stale Data
Message: Exception saving work item
Details: Exception saving work item
com.ibm.team.workitem.common.model.MultiStaleDataException: Stale Data
at com.ibm.team.workitem.common.internal.util.Utils.checkSaveResult(Utils.java:272)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.saveWorkItems(WorkItemWorkingCopyRegistry.java:1642)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.saveAffected(WorkItemWorkingCopyRegistry.java:1538)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.save(WorkItemWorkingCopyRegistry.java:1439)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.save(WorkItemWorkingCopyRegistry.java:1410)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.save(WorkItemWorkingCopyManager.java:115)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyImpl.save(WorkItemWorkingCopyImpl.java:221)
2 answers
I think the exception is being caused because the work item you are referencing has already been updated from a previous change and you are still referencing the old work item.
So let's say you are updating multiple attributes but each independently. The pseudo-code would be something like this ...
get work item handle
get working copy
edit attribute 1
save working copy
get fresh copy of work item
get working copy
edit attribute 2
save working copy
get fresh copy of work item
...
So let's say you are updating multiple attributes but each independently. The pseudo-code would be something like this ...
get work item handle
get working copy
edit attribute 1
save working copy
get fresh copy of work item
get working copy
edit attribute 2
save working copy
get fresh copy of work item
...
// get fresh copy
workItem = workItemServer.findWorkItemById(workItem.getId(),
IWorkItem.FULL_PROFILE, monitor);
Actually the problem might be, that after doing:
A disconnect should be performed. Else you will always access the same work item (cached) on subsequent calls to the manager:
wcManager.connect(handle, profile, monitor);
A disconnect should be performed. Else you will always access the same work item (cached) on subsequent calls to the manager:
public void disconnectWCPYManager(IWorkItemHandle wihdl) { getWorkItemClient().getWorkItemWorkingCopyManager().disconnect(wihdl); }