This content has been marked as final.
Show 2 replies
-
1. Re: IllegalStateException when trying to remove CMR
imsathya Sep 9, 2004 10:56 PM (in response to imsathya)Answering my own post.
The issue is that when a remove() command is issued on a bean, the container proceeds to delete the database record and also update the CMR field object - Collection or Set. So the iterator becomes invalid because the state of Collection object through which it is iterating has changed. I dont know whether there is any recommended solution to this - but the easiest workaround I put in was to save the references to the related bean objects in another Collection and iterate through that.
Thus :Collection allAddresses = getAddresses(); Iterator iterator = allAddresses.iterator(); Vector tmp = new Vector(); while(iterator.hasNext()) { AddressLocal oldObj = (AddressLocal) iterator.next(); tmp.add(oldObj); } for(Enumeration e = tmp.elements();e.hasMoreElements();) { AddressLocal oldObj = (AddressLocal) e.nextElement(); oldObj.remove(); }
This resolved the problem and the deletion went through fine !
Any other clear approaches ?
Thanks,. -
2. Re: IllegalStateException when trying to remove CMR
captrespect Dec 20, 2004 11:28 AM (in response to imsathya)just call iterator.remove() right before you call the remove() on the bean.