3 Replies Latest reply on Jul 26, 2011 5:00 PM by rhauch

    iff propertydefinition is 'protected' > ConstraintViolationException: Cannot find a definition for the property

    gbrits

      Hi, I'm evalutating Modeshape (and JCR in general)  in a test-app, and I'm hitting the following:

       

      Given the nodetype definition ((in CND)

       

      [faw:Tag] > mix:title, nt:base

          orderable

          - faw:title2 (string)

          mandatory protected

          + * (nt:base) = faw:Tag version

       

      I'm getting the following error when setting the property 'faw:title2' for the first time:

       

      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: []

                at org.modeshape.jcr.SessionCache$NodeEditor.setProperty(SessionCache.java:1136)

                at org.modeshape.jcr.SessionCache$NodeEditor.setProperty(SessionCache.java:1040)

                at org.modeshape.jcr.AbstractJcrNode.setProperty(AbstractJcrNode.java:1672)

                at models.jcr.GenericJcrDTO.buildNode(GenericJcrDTO.java:138)

                at models.jcr.GenericJcrDTO.save(GenericJcrDTO.java:159)

                at controllers.Application.saveTag(Application.java:203)

      ...............

       

      When I remove the 'protected' attribute (as per below) all goes well.

      [faw:Tag] > mix:title, nt:base

          orderable

          - faw:title2 (string)

          mandatory

          + * (nt:base) = faw:Tag version

       

      My first reaction was that  ' faw:title2' may already have been set and that I'm trying to overwrite it. Because it's 'protected' it should throw an error (Which may have been replaced by the above error-message when 'bubbling-up) .

      Howewer, I've tripled-checked that I'm only setting the property-value once, so that can't be it.

       

      Any ideas what might be the problem?

       

      Thanks,

      Geert-Jan

       

       

      p.s: using Modeshape 2.6.0.Beta1

        • 1. Re: iff propertydefinition is 'protected' > ConstraintViolationException: Cannot find a definition for the property
          rhauch

          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 protected

           

          Here, 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

            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

              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.