The child node created by your addNode(name) call has a node type that does
not declare "sling:resourceType" as an allowed property for the node.

So you would either need to use the addNode variant (see [1]) that
specifies a primary nodetype for the new node that does allow that
property, or add a mixin type that adds the property declaration.

For example:

//use a some primary node type where 'sling:resourceType' is already
allowed
node.addNode(name, "nt:unstructured");

or:

//create a child using the default primary node type
Node child = node.addNode(name);
//add mixin type (see [2]) to make sure the 'sling:resourceType' property
is allowed
child.addMixin("sling:Resource");


1.
http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#addNode(java.lang.String,
java.lang.String)
2,
http://www.day.com/maven/jsr170/javadocs/jcr-2.0/javax/jcr/Node.html#addMixin(java.lang.String)



On Sun, Jun 2, 2013 at 9:24 AM, Christian Eugster <[email protected]
> wrote:

> Hi,
>
> I checked the internet resources (google, sling website etc) as good as I
> can, but have not found a answer that I could follew to the following
> problem:
>
> I want to add Nodes to a sling repository by a service component. The
> component references SlingRepository. After getting a Session from
> loginAdministrative (thanks to Bertrand Delacretaz who showed me that way)
> I check if the node in question is already added (parent.hasNode(name). If
> yes, I get it (getNode(name) else I add a new node to the parent node with
> addNode(name).
>
> Because it is content I want to add the "sling:resourceType" property:
>
> documentNode.setProperty("**sling:resourceType", "thun/documents");
>
> but get a ConstraintViolationException saying
>
> no matching property definition found for {http://sling.apache.org/jcr/**
> sling/1.0}resourceType<http://sling.apache.org/jcr/sling/1.0%7DresourceType>
>
> What am I doing wrong?
>
> Thank you
>
> Christian
>
>
> --
> ****************************************
> Christian Eugster
> Grissian 14
> I-39010 Tisens
> 0039 0473 420 873
> 0041 79 594 85 45
> [email protected]
>

Reply via email to