Space Cadet
Space Cadet

Reputation: 403

JCR importXML method throws InvalidItemStateException on HippoCMS

I’m using the JCR Session interface to import a node (an XML file in the JCR specification) into my HippoCMS repository. I’ve written code that consumes the file and but am having difficulty saving it to the repo. The exception is thrown at the session.getWorkspace().importXML() line in the following code.

public boolean importContent(InputStream inputStream, String path) throws JCRSessionException {
    
    try {
        session.getWorkspace().importXML(path, inputStream, IMPORT_UUID_COLLISION_REPLACE_EXISTING);
    } catch (RepositoryException e) {
        throw new JCRSessionException(JCR_REPOSITORY_ERROR, e.getMessage());
    } catch (IOException e) {       
        return false;
    }
    
    return true;
}

The UUID of the node I’m importing is e33ea15d-1735-49ed-a2bc-3d18de04864d but when I try to import it fails because of an InvalidItemStateException saying “Could not find child 029d9c48-5825-4d49-bb4c-2ebb94f73df4 of node e33ea15d-1735-49ed-a2bc-3d18de04864d”.

I’ve checked the contents of the XML file and that child node UUID isn’t in there, so I’m not sure where it came from. The issue also only occurs when specify the condition IMPORT_UUID_COLLISION_REPLACE_EXISTING. If I create new UUIDs upon import, it works fine (albeit it creates a duplicate copy of the node). The XML file itself seems valid as I’ve tested importing it via the “XML Import” feature on the console and it imports successfully. Any help would be appreciated.

UPDATE:

The issue was occurring because prior to the importContent() method being called, I was calling a separate method that removed an existing node at the location path but I hadn't saved the changes. This however isn't an ideal fix because if something goes wrong during importContent() I want to be able to roll back the transaction. I've tried refreshing the session right before I call the importXML method but this results in the same problem - InvalidStateException

Upvotes: 1

Views: 91

Answers (1)

Jasper Floor
Jasper Floor

Reputation: 553

It's hard to say for sure, but this might be an index error. I suggest you run an index consistency check or rebuild the index. If that is not the case please also provide the complete stack trace.

https://documentation.bloomreach.com/13/library/administration/maintenance/checking-and-fixing-index-inconsistencies.html

Upvotes: 0

Related Questions