Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

When trying to rename a node in AEM getting 'unresolved conflicts' error

Avatar

Level 3

Hi,

 

I am trying to rename a node using session.move() method, but getting the following error:

 

CODE: 

private void renameColorProductNodes(Session session, String colorCode, String parentSku, Node productNode)
    throws RepositoryException {
        if (productNode.hasNodes()) {
            NodeIterator nodeItr = productNode.getNodes();
            while (nodeItr.hasNext()) {
                Node currentNode = nodeItr.nextNode();
                if(currentNode.getName().contains(colorCode)) {
                    String currentNodePath = currentNode.getPath();
                    String replacedPath = currentNodePath.replace(TRASH_IMAGE_PREFIX.concat(parentSku).concat(UNDERSCORE).concat(colorCode), parentSku);
                    session.move(currentNodePath, replacedPath);
                }
            }
        }
        session.save();
    }

 

 

ERROR:

javax.jcr.InvalidItemStateException: OakState0001: Unresolved conflicts in /content/dam/torrid/pdp-assets/138/861/13886120/06452/Trash
at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:238) [org.apache.jackrabbit.oak-api:1.22.6]
at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:213) [org.apache.jackrabbit.oak-api:1.22.6]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryException(SessionDelegate.java:669) [org.apache.jackrabbit.oak-jcr:1.22.6]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegate.java:495) [org.apache.jackrabbit.oak-jcr:1.22.6]
at org.apache.jackrabbit.oak.jcr.session.SessionImpl$8.performVoid(SessionImpl.java:424) [org.apache.jackrabbit.oak-jcr:1.22.6]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.performVoid(SessionDelegate.java:273) [org.apache.jackrabbit.oak-jcr:1.22.6]
at org.apache.jackrabbit.oak.jcr.session.SessionImpl.save(SessionImpl.java:421) [org.apache.jackrabbit.oak-jcr:1.22.6]
at com.adobe.granite.repository.impl.CRX3SessionImpl.save(CRX3SessionImpl.java:208) [com.adobe.granite.repository:1.6.28.CQ650-B0001]

 

Any help would be appreciated.

 

Thanks,

Nandan

8 Replies

Avatar

Community Advisor

Hi @nandan123 , This occurs when resource is modified by concurrent sessions.
Can you try session.refresh(true) before saving the session.


Hope this helps,
Krishna

Avatar

Level 3

Hi @krishna_sai , thanks for your reply

I added 

 session.refresh(true);
 session.save();
but still getting the same error.

Avatar

Community Advisor

@nandan123 

There is no explicit method to rename node in JCR, It can be done only by move method.

Since move method change the order of node but It can be reorder.

JCR 2.0: 23 Orderable Child Nodes (Content Repository for Java Technology API v2.0)

Avatar

Level 3

@Jagadeesh_Prakash Thank you for your reply,

 

When I try renaming a node, getting this ERROR, how do I solve this?

Avatar

Level 3

@Jagadeesh_Prakash 

javax.jcr.InvalidItemStateException: OakState0001: Unresolved conflicts in /content/dam/torrid/pdp-assets/138/861/13886120/06452/Trash
at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:238) [org.apache.jackrabbit.oak-api:1.22.6]
at org.apache.jackrabbit.oak.api.CommitFailedException.asRepositoryException(CommitFailedException.java:213) [org.apache.jackrabbit.oak-api:1.22.6]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.newRepositoryException(SessionDelegate.java:669) [org.apache.jackrabbit.oak-jcr:1.22.6]
at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.save(SessionDelegate.java:495) [org.apache.jackrabbit.oak-jcr:1.22.6]

Avatar

Community Advisor

Hi @nandan123 ,

 

Since the issue is because of multiple sessions/threads are concurrently trying to access/update the same node, I think you should consider using Synchronization (Synchronized method in OSGI Service). This will make sure that  the code is not being executed in parallel. Though this might hit performance so just be cautious.

 

BTW, what is the use case where the code is being executed, workflow?

 

Good reads-

https://blogs.perficient.com/2017/12/05/2-common-concurrency-pitfalls-in-aem-and-how-to-avoid-them/

https://www.javatpoint.com/synchronization-in-java

 

Thanks,

Ritesh Mittal

Avatar

Level 3

@Ritesh_Mittal Thank you for your reply,

 

This code is a part of service which is called in a servlet.

I tried adding synchronized for this method, still getting same error.