Cris,
Cloning an array before iterating over it would do the trick (leave the
rest of the code unchaged):
List tempList = new ArrayList(document.getDocumentWorkflowArray());
Iterator workflowIter = tempList.iterator();
To make it even simpler than that you can set delete rule for relationship
from DocumentWorkflow to Document to "nullify" in the modeler. In this
case you won't need "removeFromDocumentWorkflowArray" line as it will
happen automatically (you'd still need to iterate over a copy of the
relationship list).
And finally using iter.remove() in combination with context.deleteObject()
should also work, though I haven't tested it myself.
Andrus
> Hi,
>
> I'm having a little confusion determining the proper way to delete
> DataObjects through a relationship. I have a Document object which has a
> series of dependent DocumentWorkflow objects in a relationship. I am
> trying to delete them as follows:
>
> Iterator workflowIter =
> document.getDocumentWorkflowArray().iterator();
> while (workflowIter.hasNext()) {
> DocumentWorkflow docWorkflow = (DocumentWorkflow)
> workflowIter.next();
> document.removeFromDocumentWorkflowArray(docWorkflow);
> context.deleteObject(docWorkflow);
> }
>
> This not surprisingly generates a ConcurrentModificationException. Just
> calling context.deleteObject removes them from the database, but does
> not update the Document object graph, which leads to Fault errors when
> accessing the getDocumentWorkflowArray property later on.
>
> Likewise, using a DeleteQuery does not update the Document object graph.
> I can't invalidate the Document, because it has changes which must be
> processed in the same transaction.
>
> Is it safe to call iter.remove() instead of
> removeFromDocumentWorkflowArray, which calls removeToManyTarget? If not,
> how can I reliably remove all objects in a given relationship?
>
> Thanks!
>
> Cris
This archive was generated by hypermail 2.0.0 : Tue Feb 01 2005 - 15:57:12 EST