3 Replies Latest reply on Dec 4, 2014 9:10 AM by hchiorean

    Reordering reference list properties

    javagirlie

      Hello modeshape team,

       

      we are using references and weak references in ordered collections (lists) like in the following example:

         @JcrReference(weak = true)

         private List<Content> contents;

       

      We have discovered difficulties in reordering the elements in such lists.

      The elements of the list are stored in the correct order on initial save, but if we reorder the elements in the list and update the node (adding no additional elements and removing none of the existing elements) the indices of the list entries are not updated accordingly.

       

      The reason may be located in SessionNode.updateReferences - there is a comment 'if an existing reference property was just updated with the same value, it is a no-op so we should just remove it from the list of changed properties'.

      In our case the reference property has changed (even if it's only the indices of the collection elements that have changed) but the changes are not persisted as the collection elements are still the same.

       

      We have upgraded to modeshape 4.1 today, but it's the same using modeshape 4.0.

       

      Is there another way of handling such reordering of list reference elements?

       

      Thanks in advance,

      Susanne

        • 1. Re: Reordering reference list properties
          hchiorean

          I don't really understand the annotation/code, but according to the JCR spec:

          23.6 Properties are Never Orderable

          Properties are never client orderable, the order in which properties are returned by Node.getProperties() is always maintained by the implementation and can change at any time.

          So unless the references get corrupted somehow (i.e. values are lost on edit) - in which case this would be a bug, IMO it's not reasonable to expect a consistent order. Internally we are storing properties in "insertion order", but that's an implementation detail and it's not a "client-contract".

          Conceptually, I don't understand why having a particular order to a List of references would/should matter.

          • 2. Re: Reordering reference list properties
            javagirlie

            In our case, the list contains references to e.g. articles or documents and those lists can be edited/sorted by an author, hence the order of the references in the list is important for us.

             

            @JcrReference is an annotation from the JCROM framework we are using for mapping repository representations to java objects (https://code.google.com/p/jcrom/).

            • 3. Re: Reordering reference list properties
              hchiorean

              ok, the use-case makes sense. Feel free to open an enhancement request for this.