I believe jcr:created is a protected JCR property which means it can only be 
set by the repository. This constraint is enforced by JCR implementation, not 
by Sling.
As Steven suggested remove the line that explicitly sets it and it should work. 
If you have a use case that requires setting a “created” date explicitly you 
should define an application specific property that your application should be 
able to interpret.  

> On Sep 20, 2016, at 6:25 AM, Steven Walters <kemu...@gmail.com> wrote:
> 
> A) Sling expects the mixin types to passed as their raw String values
> and not as the JCR NameValue type.
> 
> The fact that the JCR NameValue type is being utilized instead is
> causing the error you are seeing as the Sling functionality converted
> it to a String (incorrectly) causing it to become invalid to the JCR
> expectations causing an exception on trying to add the corrupted mixin
> type.
> 
> B) jcr:created is specifically handled by the JCR system, so Sling
> refuses to be the writer/modifier of the property, silently ignoring
> any attempts at setting/modifying the value.
> 
> Therefore, once you remove the attempt at setting jcr:created and
> correct the jcr:mixinTypes value, you should be allowed to create the
> resource.
> From there, the JCR system should automatically add the jcr:created
> due to the mixin Type.
> 
> On Tue, Sep 20, 2016 at 9:46 PM, Roy Teeuwen <r...@teeuwen.be> wrote:
>> Hello all,
>> 
>> I am trying to create an nt:unstructured resource programatically, which 
>> contains a jcr:created property, but I don’t seem to find a way to add this 
>> programatically, nor how to add a jcr:mixinType (which would make it 
>> possible).
>> 
>> I tried the following, but it isn’t working:
>> 
>> Resource myResource = resourceResolver.getResource("/myresource");
>> Map<String,Object> properties = new HashMap<String,Object>();
>> properties.put("jcr:primaryType", "nt:unstructured”);
>> properties.put("jcr:mixinTypes", new NameValue[] 
>> {NameValue.valueOf("mix:created")});
>> properties.put(“jcr:created”, Calendar.getInstance());
>> Resource dummy = resourceResolver.create(myResource, "dummy", properties);
>> resourceResolver.commit();
>> 
>> I get the following exception:
>> 
>> java.lang.IllegalArgumentException: Value can't be stored in the repository: 
>> org.apache.jackrabbit.value.NameValue@0
>> 
>> 
>> Can anyone tell me on how to add this on creation time?
>> 
>> Thanks!
>> Roy

Reply via email to