- Posted by: Frank Stephan
- Posted on: June 01 2002 16:43 EDT
I read in Prof EJB from Wrox that an IllegalStateException could be thrown if a CMR collection is changed implicitly while walking over the collection using an iterator.
I have a One-To-Many relationship between Product and Component. Now when I walk through the collection components of entity Product and try to remove a component using iterator.remove() I get an IllegalStateException, too.
What's going wrong here? Where do I get that exception, although I remove the entity from the collection explicitely?
This might be a ConcurrentModificationException, but I don't really know because I'm not entirely sure if your exception is coming from the EJB container for something EJB specific, or something to do with the collection. This error would be thrown by the iterator.
From the java docs
"For example, it is not permssible for one thread to modify a Collection while another thread is iterating over it."
Try splitting up the iterator loop from the remove call, if you still ge the same error then you know its not this.
..Maybe you forgot to call itr.next( ) before calling itr.remove( ) !!