11 Replies Latest reply on Feb 17, 2011 3:57 AM by dimonv

    Weak referencies store/retrieve

    dimonv

      Hi all,

       

      on using of the WEAKREFERENCE type I face following issue:

      I have a node type having a property of the type 'WEAKREFERENCE'. The WEAKREFERENCE values can be set to the property of a node, but after retrieving of the node the type the value switches to REFERENCE. This behavior. As consequences:

      • such WEAKREFERENCE values cannot be used for assignment of the WEAKREFERENCE-properties
      • the specification for comparison of the JCR values is broken
      • the referential integrity "strikes" on e.g. an attempt to remove a node if it's referenced.

       

      Did anybody face the same issue?

        • 1. Weak referencies store/retrieve
          rhauch

          That sounds odd, but all of what you're seeing is certainly possible if the WEAKREFERENCE property is somehow being turned into a REFERENCE property. This clearly sounds like a bug, so please log an issue in JIRA.

           

          Are you using a node type with a WEAKREFERENCE or REFERENCE property definition? If so, can you share it?

           

          Can you provide the sample code that sets the property, retrieves the node and property, and performs the comparison? Doesn't need to be a full-on test case; code snippets would be enough for us to know exactly what you're doing so we can replicate it.

           

          Thanks!

          • 2. Weak referencies store/retrieve
            dimonv

            Here is s snapshot of the relevent node type definition:

            ['org:identity'] > nt:unstructured, mix:referenceable , mix:shareable

            ['org:person'] > 'org:identity', mix:referenceable, mix:shareable

            ...

            ['org:identity-group'] > 'org:identity'

              - 'org:name' (String) mandatory

              - 'org:members' (weakreference) = 'org:person' MULTIPLE INITIALIZE

             

            and the codesnippet of the property assignment:

                      Node groupNode; //"org:identity-group"

                      Node person; // "org:person"

            ...

                    Set<Value> membersSet = new HashSet<Value>();

                    if (groupNode.hasProperty("org:members")) {

                        Value[] members = groupNode.getProperty("org:members").getValues();

                        List<Value> membersList = Arrays.asList(members);

                        membersSet.addAll(membersList);

                    }

                    Value newMember = getSession().getValueFactory().createValue(person.getIdentifier(), PropertyType.WEAKREFERENCE);

                    membersSet.add(newMember);

                    Value[] membersValues = new Value[membersSet.size()];

                    membersValues = membersSet.toArray(membersValues);

                    groupNode.setProperty("org:members", membersValues, PropertyType.WEAKREFERENCE);

                    getSession().save();

                    getSession().logout();

             

            If I retrieve the groupe node:

                               QueryManager queryManager = session.getWorkspace().getQueryManager();

                               Query q = queryManager.createQuery("SELECT * FROM 'org:identity-group' WHERE ('org:name' = '" + name + "')"

            , "JCR-SQL2");

                                javax.jcr.query.QueryResult result = q.execute();

                                    Node groupNode = null;

                                    for (NodeIterator ni = result.getNodes(); ni.hasNext();) {

                                        groupNode = ni.nextNode();

                                    }

                                    return groupNode;

             

            Anyway between assignment, storing or retrievig the type of the value switches from WEAK- to REFERENCE.

            I hope it'll help.

            • 3. Weak referencies store/retrieve
              rhauch

              That's exactly what we'll need to reproduce. Thanks!

              • 4. Weak referencies store/retrieve
                dimonv

                I'm not sure but I have a suspicion that it is the method org.modeshape.jcr.SessionCache.findBestPropertyDefintion(...) which chooses a wrong property type.

                • 5. Weak referencies store/retrieve
                  rhauch

                  Thanks. I logged this as MODE-1092 and targeted it as critical for the next release.

                  • 6. Re: Weak referencies store/retrieve
                    dimonv

                    I think I got a solution for it. See my comments to MODE-1092.

                    • 7. Re: Weak referencies store/retrieve
                      rhauch

                      As mentioned on MODE-1092, I have a pull-request for the changes to fix this, and am waiting for a review. Stay tuned.

                      • 8. Re: Weak referencies store/retrieve
                        dimonv

                        Since I'm not familiar with GitHub, could you write me what does it mean and if you expect any actions from my side?

                        • 9. Re: Weak referencies store/retrieve
                          rhauch

                          No, you don't need to do anything at the moment. Our Git repository on GitHub is our master repository, and once we have some 'proposed' changes that appear to work, we create a GitHub pull request with those changes and ask that some other developer review the changes. Once approved, we'll merge it into the 'master' branch on the official GitHub repository.

                           

                          My previous post was just to keep you (and anyone else) informed of the progress.

                          • 10. Weak referencies store/retrieve
                            rhauch

                            The fix for MODE-1092 has been committed to the 'master' branch, and will be included in the next release. I've marked the issue as resolved, but if you're able to test 'master' and still find a problem, please reopen the issue.

                             

                            Thanks again, Dmitri, for all the help with this issue!

                            • 11. Weak referencies store/retrieve
                              dimonv

                              You're welcome, Randall. Thank you for the fast fixing. Community is great:-)