Search code examples
javajcrmagnolia

Node setProperty gives RepositoryException in Magnolia CMS due to Constraint Violation


I need to set all the following properties for a node and I am getting a RepositoryException

'jcr:createdBy': 'admin'
'hideInNav': 'true'
'mgnl:template': 'something'
'jcr:created': '2020-01-09T14:14:13.555+01:00'
'mgnl:created': '2020-01-09T14:14:13.555+01:00'
'mgnl:createdBy': 'superuser'
'jcr:uuid': 'df7227a7-39e2-4e15-8d26-16b8b0657049'
'title': 'Sitemap'
'mgnl:lastModified': '2020-01-09T16:04:11.820+01:00'
'jcr:primaryType': 'mgnl:page'
'mgnl:lastModifiedBy': 'superuser'

This is the code that I use in a loop to setup the above properties for a node:

try {
     String value= (String)entry.getValue();
     node.setProperty(entry.getKey(), value);
           }

} catch (ItemNotFoundException e) {
                // TODO Auto-generated catch block
            e.printStackTrace();
} catch (RepositoryException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
}

and the stack trace for the RepositoryException is:

javax.jcr.nodetype.ConstraintViolationException: Unable to perform operation. Node is protected.
        at org.apache.jackrabbit.core.ItemValidator.checkCondition(ItemValidator.java:276)
        at org.apache.jackrabbit.core.ItemValidator.checkModify(ItemValidator.java:248)
        at org.apache.jackrabbit.core.PropertyImpl.checkSetValue(PropertyImpl.java:278)
        at org.apache.jackrabbit.core.PropertyImpl.setValue(PropertyImpl.java:726)
        at org.apache.jackrabbit.core.NodeImpl$SetPropertyOperation.perform(NodeImpl.java:2058)
        at org.apache.jackrabbit.core.NodeImpl$SetPropertyOperation.perform(NodeImpl.java:2002)
        at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
        at org.apache.jackrabbit.core.NodeImpl.setProperty(NodeImpl.java:1924)
        at org.apache.jackrabbit.core.NodeImpl.setProperty(NodeImpl.java:1894)

Any suggestions? Are there any limitations on what properties you can or cannot set?


Solution

  • Simple answer is: don't.
    You should not be setting value for any of the jcr: or mgnl: properties. If you try to set value for the reminder, it will work just fine.