Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

java.lang.IllegalArgumentException: Value for key (property name) can't be put into node

Avatar

Level 2

Hi everyone,

                     i am trying to add/update new/existing property with value to asset metadata and when i say resolver.commit(), it results in following exception

java.lang.IllegalArgumentException: Value for key (property name here) can't be put into node: [Ljava.lang.String;@1455d8b2

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:458)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:47)

aused by: javax.jcr.version.VersionException: Cannot set property. Node [path/to/asset/jcr:content/metadata] is checked in.

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$36.checkPreconditions(NodeImpl.java:1404)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.prePerform(SessionDelegate.java:615)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:205)

at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1399)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:378)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:453)

... 19 common frames omitted

E2: java.lang.IllegalArgumentException: Value for key (some other property)  can't be put into node: update (value)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:458)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:47)

aused by: javax.jcr.version.VersionException: Cannot set property. Node [path/to/asset/jcr:content/metadata] is checked in.

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.checkPreconditions(NodeImpl.java:1368)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.prePerform(SessionDelegate.java:615)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:205)

at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1363)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:351)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:455)

... 21 common frames omitted

When i reprocess the same asset for creating/updating same metadata property, it works well. Please suggest any improvements here.

21 Replies

Avatar

Level 10

Please provide the exact steps you are performing so community can try and reduplicate this issue.

Avatar

Level 2

Thanks for letting me know, smacdonald2008

Here is the code snippet for the same,

String customValue = "update";

Resource assetRsc = resolver.getResource("path/to/asset/metadata");

if(assetRsc !=null) {

    ModifiableValueMap properties = assetRsc.adaptTo(ModifiableValueMap.class);

     properties.put("custom_property", customValue );

     // some more properties to be set here

     saveToRepo(resolver);

}

private void saveToRepo(ResourceResolver resolver){

try {

resolver.commit();

} catch (PersistenceException e) {

logger.error("Exception while saving changes :", e);

}

}

I hope this helps understanding. Please let me know, if any other information is required.

Avatar

Employee

The code looks good. What is the exact value you are trying to put?

Avatar

Level 2

Hi rmahendr

                          the values(create/update/delete) i use are of string type. The second property takes string[] type values.

Thanks & Regards,

Radhakrishna.

Avatar

Community Advisor

Try Asset API. Asset ("The Adobe AEM Quickstart and Web Application.")

Asset is created by AssetManager and can be retrieved either via AssetManager or by adapting a asset Resource to an Asset.

     eg:

     // to create an asset

     AssetManager assetManager = resolver.adaptTo(AssetManager.class);

     Asset newAsset = assetManager.createAsset("/path/to/asset/document.pdf");

     // to get an existing asset

     Asset asset = assetManager.getAsset("/path/to/asset/document.pdf");

     // to get asset by adapting

     Asset asset = resource.adaptTo(Asset.class);

Asset properties can be retrieved or set by adapting it to a ValueMap.

     eg:

     // to get Asset properties value map

     ValueMap map = asset.adaptTo(ValueMap.class);

/Brijesh Yadav

Avatar

Level 2

Hi Yadav Brijesh,

                            thanks for your suggestion. I would look to understand your suggestion using Asset API. What advantage are we going to get when compared to Resource. Can you please help putting your view here and how that helps this problem to be solved?

Thanks & Regards,

Radhakrishna.

Avatar

Level 10

When working with AEM - if there is a corresponding API - like Asset Manager API, Tag Manager API, etc, you should ways use these strongly types APIs when programmatically working with AEM.

Here is URL to the Javadocs - "The CQ5 Quickstart and Web Application."

** MAY MAKE A GOOD Ask the AEM Community Session**

Avatar

Level 2

Hi smacdonald2008,

                                    thanks for making a point to use specific API when using corresponding functionality. I do follow Yadav Brijesh and your recommendations here on. It would be great information for everyone, if we have exact difference between them.

I am very much interested to know about this exception.

Thanks & Regards,

Radhakrishna.

Avatar

Level 2

Hi smacdonald2008,

                                    Could you please let me know, if there is any update about this?

Thanks & Regards,

Radhakrishna.

Avatar

Level 10

We reached out again.  This use case is now on the  Community ToDo list for examples that appear in HELPX articles. Best way to update Asset Metadata using  an AEM API

Avatar

Level 2

Hi smacdonald2008,

                                  thanks for your quick update. Usage of API is ok. Is there any chance of write up on difference between Asset Manager API and using resolver and then modifiable map for updates? It would be great help here for understanding more.

Thanks & Regards,

Radhakrishna.

Avatar

Level 10

Sling Resource: This is based on apache sling,  When you use resource, you treat each path as a resource and use resource methods. That's what you do when you have a asset path. You treat is as a resource and add / remove properties.

AssetManager API: It's a high level API created for AEM assets on top of JCR node API. So instead of directly using jcr, they have abstracted out the methods

Avatar

Level 2

Hi Edubey,

                   thanks for your information here! I have got some more specific information that can be found on https://www.slideshare.net/connectwebex/jcr-sling-or-aem-which-api-should-i-use-and-when

Thanks & Regards,

Radhakrishna.

Avatar

Employee Advisor

Have you seen that the exception contains this line:

> javax.jcr.version.VersionException: Cannot set property. Node [path/to/asset/jcr:content/metadata] is checked in.

You need to check out that node first to continue to save() properties. Not sure why it has been checked-in without being checked-out.

Jörg

Avatar

Level 2

Hi Jörg Hoh,

                        yes, i could see version exception as follows,

Caused by: javax.jcr.version.VersionException: Cannot set property. Node [/content/dam/path/to/asset/jcr:content/metadata] is checked in.

at org.apache.jackrabbit.oak.jcr.session.NodeImpl$36.checkPreconditions(NodeImpl.java:1404)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.prePerform(SessionDelegate.java:615)

at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:205)

at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1399)

at org.apache.jackrabbit.oak.jcr.session.NodeImpl.setProperty(NodeImpl.java:378)

at org.apache.sling.jcr.resource.internal.JcrModifiableValueMap.put(JcrModifiableValueMap.java:453)

I am wondering who is checking in this asset. Is there any way to figure out?

Thanks & Regards,

Radhakrishna.

Avatar

Employee Advisor

Hi,

that's not immediately visible. I remember cases where this happened for pages on "pagemanager.createVersion()", could be for assets the same. In general, node.checkin() and node.checkout() are part of the versioning. Maybe this can help you to track down suspect log entries.

Jörg

Avatar

Level 10

Did all these community suggestions help you resolve this issue?

Avatar

Level 2

Hi  smacdonald2008,

                                    i have received lot of information here from all the members. I am thankful to them. This is is not so frequent as it depends on the load on the instance. I am awaiting full load on the instance and to investigate more. I update here my findings once i receive them that could help others.

Thanks & Regards,

Radhakrishna.