RuntimeException - ReadOnlyException
hello to everybody. I have a big problem! I have a List which i scan. During the scan i have to check if the object into the List has some parameters. What i'd like to do is remove the object if the parameters are not good and than continue to scan the list. How can i do?
i tried to do this:
while (it.hasNext())
{
BonusToken bt=(BonusToken)it.next();
if (bt.getBonusGotDate()!=null) {
bonusTokenList.remove(bt);
break;
}
}
but it doesn't work, it generates the Exception below:
java.lang.RuntimeException ... Read only persistent object.
Where is the mistake?I tried without "break" but it doesn't works anyway
Please help me!
# 1
What should have break to do with it?
The important information is missing: what is the source of the iterator and how does the source get created? It seems, that it is a read only collection implementation and thus you cannot remove items. Further, you should use the iterators remove operation to prevent concurrent modification issues.
# 7
Copy it. Your code is flawed anyway, see below
List<BonusToken> list = new ArrayList<BonusToken>(persistentCollection);
Iterator<BonusToken> it = list.iterator();
while (it.hasNext())
{
BonusToken bt=(BonusToken)it.next();
if (bt.getBonusGotDate()!=null) {
it.remove();// => NB you must remove via the iterator when iterating
break;
}
Note that this removal only happens in memory, not in the persistent collection.
ejpa at 2007-7-12 15:20:40 >

# 8
So are you going to remove them from the persistent layer or do you need the reduced list locally only? In the first case, you will have to use the persistent layer API to remove the entries, in the latter, you should create your own list and add the ones you need.