-
1. Re: iff propertydefinition is 'protected' > ConstraintViolationException: Cannot find a definition for the property
rhauch Jul 26, 2011 4:29 PM (in response to gbrits)Section 3.7.2.2 of the JCR 2.0 specification states the following:
If an item I is declared protected it is repository-controlled... Additionally, if I is a property, its being repository-controlled also implies that its value is under the control of the repository and can change at any time, before or after save. See §3.7.2.3.2 Auto-Created and Protected.
In other words, a repository implementation can define protected properties, but users of the repository may not define new protected property definitions. Additionally client applications may not change protected properties.
An example of a protected property is "mix:created" mixin, which is defined as follows:
[mix:created] mixin
- jcr:created (DATE) autocreated protected
- jcr:createdBy (STRING) autocreated protectedHere, the "jcr:created" timestamp is automatically set by the repository to the current time whenever a node with this mixin is changed. Likewise, the "jcr:createdBy" value is automatically set at the same time to the value of the "session.getUserID()" method.
javax.jcr.nodetype.ConstraintViolationException: Cannot find a definition for the property named 'faw:title2' on the node at '/etc/tags/asdasd' with primary type 'faw:Tag' and mixin types: []
That message really means that ModeShape cannot find a *non-protected* definition for the property named "faw:title2". If you think this is unclear, you could log an enhancement request in our JIRA to improve that error message. I'm not sure that our logic can disambiguate between all the possible reasons *why* a valid property definition couldn't be found (there are a lot of combination of reasons), so that might complicate improving the message.
Hope this helps!
Best regards
-
2. Re: iff propertydefinition is 'protected' > ConstraintViolationException: Cannot find a definition for the property
gbrits Jul 26, 2011 4:43 PM (in response to rhauch)Thanks Randall, that definitely explains the error.
This changes my question to: is there a way to define that a property may me set once, and cannot be overwritten afterwards?
Analogously to 'final' in Java. I assumed it was 'protected', as you may have guessed :).
Quickly glancing the JCR2.0 spec around 3.7.2.2 (which you pointed at and which describe other property types) didn't turn up anything, but I would guess this would be much-asked functionality?
Thanks again,
Geert-Jan
-
3. Re: iff propertydefinition is 'protected' > ConstraintViolationException: Cannot find a definition for the property
rhauch Jul 26, 2011 5:00 PM (in response to gbrits)This changes my question to: is there a way to define that a property may me set once, and cannot be overwritten afterwards?
Analogously to 'final' in Java. I assumed it was 'protected', as you may have guessed :).
No, unfortunately there is no practical way to define a property that is initialized to an arbitrary value and never allowed to be modified. Autocreated doesn't quite work, nor do default values. Constraints might work only in the (rare) situation where the single value is known upfront and can be hard-coded into the property definition; in all other situations (like yours), constraints don't work either.
Custom authorization policies might work, but even if that does it is IMO overkill.
FWIW, I just posted the question to the JSR-333 expert group. I'll update this discussion when I hear back.