javax.jcr.InvalidItemStateException: Item seems to have been removed externally | Community
Skip to main content
October 16, 2015
Solved

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

  • October 16, 2015
  • 2 replies
  • 3109 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joerghoh

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

2 replies

Level 8
October 16, 2015

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? 

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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