InvalidItemStateException when trying to add a node
satyakishor.m Mar 13, 2013 2:51 PMWe have a batch process that reads a big excel file and creates nodes from the excel contents. I am running into InvalidItemStateException when running the batch process. But my code works fine if I comment out the versioning part in the below code or a small excel file is being used.
Following is the method that was throwing the InvalidItemStateException.
public DetailNode createChild(Token token, Reference parent, NodeType type, String name, Workspace workspace) {
Session session = null;
DetailNode detailNode = null;
try {
String cleanName = cleanPath(name);
session = this.login(token, workspace);
VersionManager vm = session.getWorkspace().getVersionManager();
Node parentNode = session.getNode(parent.getPath());
vm.checkout(parent.getPath());
String jcrNodeType = BidiJermsToJCRTypeMapping.getTypemapping().inverseBidiMap().get(type).toString();
Node childNode = parentNode.addNode(cleanName, jcrNodeType);
session.save();
vm.checkin(childNode.getPath());
vm.checkin(parentNode.getPath());
detailNode = getDetailNode(childNode);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
if(session != null) {
session.logout();
}
}
return detailNode;
}
Following is the exception stack trace.
14:08:30,863 INFO [stdout] (EJB default - 1) 2013-03-13 14:08:30,847 [EJB default - 1] ERROR c.j.s.j.jcr.impl.DaoImpl - This session tried to save changes to node with key 'cc21f74317f1e762563a66-33d4-434e-9172-50d49e7b863f', but it was removed by another session.
14:08:30,863 INFO [stdout] (EJB default - 1) org.modeshape.jcr.cache.DocumentNotFoundException: cc21f74317f1e762563a66-33d4-434e-9172-50d49e7b863f
14:08:30,863 INFO [stdout] (EJB default - 1) at org.modeshape.jcr.cache.document.WritableSessionCache.persistChanges(WritableSessionCache.java:844) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]
14:08:30,863 INFO [stdout] (EJB default - 1) at org.modeshape.jcr.cache.document.WritableSessionCache.save(WritableSessionCache.java:518) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]
14:08:30,879 INFO [stdout] (EJB default - 1) at org.modeshape.jcr.JcrSession.save(JcrSession.java:978) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]
14:08:30,879 INFO [stdout] (EJB default - 1) Wrapped by: javax.jcr.InvalidItemStateException: This session tried to save changes to node with key 'cc21f74317f1e762563a66-33d4-434e-9172-50d49e7b863f', but it was removed by another session.
14:08:30,879 INFO [stdout] (EJB default - 1) at org.modeshape.jcr.JcrSession.save(JcrSession.java:985) ~[modeshape-jcr-3.1.2.Final.jar!/:3.1.2.Final]
14:08:30,894 INFO [stdout] (EJB default - 1) at c.j.s.j.jcr.DaoImpl.createChild(DaoImpl.java:458) ~[jerms-impl.jar:na]
I am not sure exactly why I am getting this error. Am I using the versioning correctly??