Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.jcr.nodetype.ConstraintViolationException: No matching property definition: PROPERTY

Tags:

jcr

aem

When I am trying to set a property to my JCR node I am getting error

javax.jcr.nodetype.ConstraintViolationException: No matching property definition: PROPERTY.

I am a newbie to cq5. Please can someone help me to resolve this error?

like image 737
Mayur Desai Avatar asked Dec 22 '25 01:12

Mayur Desai


2 Answers

In jcr every node has a node-type (value of "jcr:primaryType").

Most node-types define a schema of properties that are allowed on that node. You cannot just add whatever property you like. It has to be defined in the schema. If you try to add and persist (commit) a property that is not defined, you get exactly this ConstraintViolationException.

So here's what likely happend: You've tried to create and store a property named "PROPERTY" on a node that has a strict schema, where that is not allowed.

If you provide more details what you tried to do exactly on what type of node, I may be able to pinpoint the problem.

like image 61
Andreas Vogl Avatar answered Dec 24 '25 10:12

Andreas Vogl


If you want to add property to a nt:file for exemple, you have to define a new mixin type and add it to your node.

This way you can add every properties you want

This simpler way is to create a CND file to define all your properties

<mc = 'http://myCompany.com/mc'>
[mc:fileProperties]
    mixin
        - mc:String1 (string)version
        - mc:String2 (string) version
        - mc:String3 (string) version
        - mc:LongString1 (string) version
        - mc:Date1 (date) version
        - mc:Date2 (date) version
        - mc:Number1 (long) version
        - mc:Number2 (long) version
        - mc:Boolean1 (boolean) version
        - mc:Boolean2 (boolean) version
        - mc:Choice1 (long) version

and you have to register your new mixin (you only have to do this once)

JackrabbitNodeTypeManager manager = (JackrabbitNodeTypeManager)session.getWorkspace().getNodeTypeManager();
InputStream cndFile = ... // Get you CND file
JackrabbitNodeTypeManager.TEXT_X_JCR_CND );

and add it to your Node

node.addMixin( "mc:fileProperties" );

Here you can do

node.setProperty( "mc:String1", "Toto" );
session.save();
like image 38
Nico Avatar answered Dec 24 '25 10:12

Nico