Expand my Community achievements bar.

SOLVED

CQ5 Unable to update a stale item: item.save() javax.jcr.InvalidItemStateException: Unable to update a stale item: item.save()

Avatar

Level 9

I am using workflow to copy lots of pdfs from one location to other dam locations based on the data and set of requirements. I am using the following code Asset damAsset = manager.createAsset(path, is, mimeType,true); where path is the destination dire and 'is' is inputstream pdf file, there is no metadata on I am applying the metadata to destination file using following statement Node node = damAsset.adaptTo(Node.class); Node mdNode = node.getNode("jcr:content/metadata"); mdNode.setProperty("pttitle", forms.getFileDisplayTitle()); Once all the files are finished I am terminating the workflow uing workflowSession.terminateWorkflow(workItem.getWorkflow());

Workflow works fine for most of the time but last file didn't set with the metadata due to following exception. This exception happens randomly once after running repeatedly for 3-4 times.

javax.jcr.InvalidItemStateException: Unable to update a stale item: item.save()at org.apache.jackrabbit.core.ItemSaveOperation.perform(ItemSaveOperation.java:262)at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)at org.apache.jackrabbit.core.ItemImpl.perform(ItemImpl.java:91)at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:329)at org.apache.jackrabbit.core.session.SessionSaveOperation.perform(SessionSaveOperation.java:65)at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)at java.lang.Thread.run(Unknown Source)Caused by: org.apache.jackrabbit.core.state.StaleItemStateException: 1f6fc642-1a20-4cac-abe5-70f903aefde4 has been modified externally at org.apache.jackrabbit.core.state.SharedItemStateManager$Update.begin(SharedItemStateManager.java:679)at org.apache.jackrabbit.core.ItemSaveOperation.perform(ItemSaveOperation.java:258
1 Accepted Solution

Avatar

Correct answer by
Level 10

There is an explanation for this in this Apache mailing list:

https://www.mail-archive.com/dev@archiva.apache.org/msg01883.html

It looks like this occurs if another process trying to access/scan the node. 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

There is an explanation for this in this Apache mailing list:

https://www.mail-archive.com/dev@archiva.apache.org/msg01883.html

It looks like this occurs if another process trying to access/scan the node. 

Avatar

Level 9

Hi Sam,

Thanks for the reply, I checked the link you sent to me, this is happening for the last file in the workflow upload process.

Node is not being used anywhere

It is an exception which causes loss of the metadata I applied to the pdf node.

I removed terminateWorkfow statement as workflow completes successfully. Initially I thought of terminating workflow but I was wrong

I cannot even catch this exception as it is thrown internally inside CQ5.

Please let me know if you have any updates.