Uploaded image for project: 'Spring Data Neo4j'
  1. Spring Data Neo4j
  2. DATAGRAPH-265

ManagedFieldAccessorSet does not follow Set contract (with remove(obj) for example)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.1.RC1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I use simple mapping. I have a husband entity containing Set of Child entities.

       
      @NodeEntity
      public class Husband {
          @GraphId
          private Long graphId;
          private String name;
          @RelatedTo(type = "has_child", direction = Direction.OUTGOING)
          private Set<Child> children = new HashSet<Child>();
      ...
      

      And Child entity:

       
      @NodeEntity
      public class Child {
          @GraphId
          private Long graphId;
          private String name;
      ...
      

      Child entity override equals/hashCode, taking nullable "graphId" and "name" into account.

      Inside transactional action, removing Child entity from parent Husband entity doesn't work via set.remove(obj), although set.contains(obj) returns true. More concretely,

      children.contains(child) == true
      but
      children.remove(child) == false

      When I drill into the matter, I discovered something strange. Inside ManagedFieldAccessorSet's remove method, you pass the call to delegate Set:

       
          public boolean remove(Object o) {
              if (delegate.remove(o)) {
                  update();
                  return true;
              }
              return false;
          }
      

      Strange thing is that my debugger shows that delegate field is plain java.util.HashSet containing the exact instance of element that I'm trying to remove ("o" parameter in remove method), but nonetheless it cannot find it inside to remove it. I tried executing contains method while debugging, and it cannot find the element also:
      delegate.contains(o) = false
      Really strange!
      But, when I try inside my debugger to copy first the contents of delegate set to my new one, and check the existence of the element, it works then. In other words:
      new HashSet(delegate).contains(o) = true

      Like delegate is some strange Set impl, but my debugger shows its just plain java.util.HashSet.

        Attachments

          Activity

            People

            • Assignee:
              mhunger Michael Hunger
              Reporter:
              vmarcinko Vjeran Marcinko
              Last updater:
              Nicolas Mervaillie
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: