Hi,
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?
TIA
Frank
-
IllegalStateException using iterator? (2 messages)
- Posted by: Frank Stephan
- Posted on: June 01 2002 16:43 EDT
Threaded Messages (2)
- IllegalStateException using iterator? by Jason McKerr on June 02 2002 21:22 EDT
- IllegalStateException using iterator? by Apurva Singh on July 16 2013 12:22 EDT
-
IllegalStateException using iterator?[ Go to top ]
- Posted by: Jason McKerr
- Posted on: June 02 2002 21:22 EDT
- in response to Frank Stephan
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.
-
IllegalStateException using iterator?[ Go to top ]
- Posted by: Apurva Singh
- Posted on: July 16 2013 12:22 EDT
- in response to Frank Stephan
..Maybe you forgot to call itr.next( ) before calling itr.remove( ) !!