Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
SOLVED

javax.jcr.InvalidItemStateException: Item seems to have been removed externally

Avatar

Level 1

Hi,

While trying to create a node under /var/<app> folder in CQ and saving it using javax.jcr.Session.save() , system is throwing the below exception. 

javax.jcr.InvalidItemStateException: Item seems to have been removed externally at org.apache.jackrabbit.core.state.SessionItemStateManager.getDescendantTransientItemStates(SessionItemStateManager.java:363)

    at org.apache.jackrabbit.core.ItemSaveOperation.getTransientStates(ItemSaveOperation.java:313)
    at org.apache.jackrabbit.core.ItemSaveOperation.perform(ItemSaveOperation.java:98)
    at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
    at org.apache.jackrabbit.core.session.SessionSaveOperation.perform(SessionSaveOperation.java:65)
    at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
    at com.day.crx.core.CRXSessionImpl.save(CRXSessionImpl.java:142)

If i understood correctly , this error could be due to some other session(probably a session created in one of the author instance in the CQ cluster) has been removing it but did not persist the removal in its session properly and holding the lock and restricting other sessions to create any new nodes under this folder /var/<app> folder.

This has not been happening when there are concurrent requests. Even at the time of one thread executing the action, system is not allowing any of the node to be created under that var/<app> folder via our app code which is using JCR API session.save method to create and save nodes under that particular folder.

Can someone please help in finding a way to resolve this exception? If my understanding is correct , is there a way to clear the lock? if we restart CQ server, will the lock be cleared?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Basically your problem is, that a session.save() happens in that tree, while your session is open; and when it wants to save nodes, JCR refuses to do so, because somehting has changed in the meanwhile. Some approaches to tackle it:

  • Do not have long-standing sessions, which accumulate write operations over time and after some time do a final session.save(); you'll run into these problems.
  • You can do a session.refresh(true) before saving. This re-reads the current state from the repo and keeps your un-saved changes in the session. For me this is more or less a workaround.

Jörg

View solution in original post

2 Replies

Avatar

Level 8

What version of AEM are you running? 

Where is the code creating the node running - in a OSGI service? Is it triggered on a schedule or by user action? 

Could you post a sample of the code? 

Avatar

Correct answer by
Employee Advisor

Basically your problem is, that a session.save() happens in that tree, while your session is open; and when it wants to save nodes, JCR refuses to do so, because somehting has changed in the meanwhile. Some approaches to tackle it:

  • Do not have long-standing sessions, which accumulate write operations over time and after some time do a final session.save(); you'll run into these problems.
  • You can do a session.refresh(true) before saving. This re-reads the current state from the repo and keeps your un-saved changes in the session. For me this is more or less a workaround.

Jörg