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

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)

0 votes



2 answers

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



// get fresh copy

workItem = workItemServer.findWorkItemById(workItem.getId(),
IWorkItem.FULL_PROFILE, monitor);

0 votes


Permanent link
Actually the problem might be, that after doing:

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

0 votes

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
× 10,939

Question asked: Apr 20 '09, 1:51 p.m.

Question was seen: 7,548 times

Last updated: Sep 30 '15, 11:11 a.m.

Confirmation Cancel Confirm