0 Replies Latest reply on Jun 23, 2006 12:19 PM by daveespo

    CMR setter method behavior

      Reading a couple of posts on this topic, I'm unclear what I should be doing when removing items from the "Many" side of my CMR (JBOSS 4.0.0)

      My code (pseudocode) reads like this:

      Collection children = parent.getChildren();
      Iterator childIterator = children.iterator();
      while(childIterator.hasNext())
      {
      MyChild child = (MyChild)childIterator.next();
      if(child.meetsSomeCriteriaForRemoval())
      childIterator.remove();
      }

      System.out.println("Num children: " + children.size());
      parent.setChildren(children);
      System.out.println("Num children: " + parent.getChildren().size());

      The issue is, the two println() calls output what I expect (they reflect that I removed some children). But when I commit the transaction and look in my DB, the records haven't been removed and when I start a new transaction, they are resurrected when I do my call to getChildren();

      I tried adding a child.remove() but that modifies the underlying Collection and my next call to next() on my Iterator failes with an IllegalStateException because of the modification to the underlying Collection.

      Should I expect that a call to setChildren() should remove() records from the database for any children that are no longer in the Collection?

      Thanks,
      Dave