When trying to rename a node in AEM getting 'unresolved conflicts' error | Community
Skip to main content
Level 2
February 13, 2023

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

  • February 13, 2023
  • 3 replies
  • 1836 views

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

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

3 replies

krishna_sai
Community Advisor
Community Advisor
February 13, 2023

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


Hope this helps,
Krishna

NandanGo1Author
Level 2
February 13, 2023

Hi @krishna_sai , thanks for your reply

I added 

 session.refresh(true);
 session.save();
but still getting the same error.
Jagadeesh_Prakash
Community Advisor
Community Advisor
February 13, 2023

@nandango1 

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)

NandanGo1Author
Level 2
February 13, 2023

@jagadeesh_prakash Thank you for your reply,

 

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

Jagadeesh_Prakash
Community Advisor
Community Advisor
February 13, 2023

@nandango1  where is the error?

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
February 13, 2023

Hi @nandango1 ,

 

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

NandanGo1Author
Level 2
February 13, 2023

@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.