remove not removing [message #389736] |
Thu, 25 June 2009 10:06 |
Tom Eugelink Messages: 825 Registered: July 2009 |
Senior Member |
|
|
I have a list of Agent2User entities as the N side of a 1-N relation that also updates the 1 side by calling the setter. This could cause a loop, but the contains-remove setup below breaks that: if the entity is still in the list, remove it, then call the setter, which will then call the remove again, but the entity will not be in the list anymore and thus the loop breaks.
The code is below and there 5 debug lines mixed in (the actual method is only 3 lines).
public void removeAgent2Users(nl.knowledgeplaza.profiler.engine.model.Ag ent2User value)
{
System.out.println("agent2user list size = " + this.agent2Users.size());
for (Agent2User a : this.agent2Users) System.out.println(">>" + a + " / " + value + " / " + a.equals(value) );
if (value != null && this.agent2Users.contains(value))
{
boolean lWasRemoved = this.agent2Users.remove(value);
System.out.println("WasRemoved = " + lWasRemoved);
System.out.println("agent2user list size after remove = " + this.agent2Users.size());
for (Agent2User a : this.agent2Users) System.out.println(">>" + a + " / " + value + " / " + a.equals(value) );
value.setAgent( (Agent)null );
}
}
Output:
agent2user list size = 1
>>nl.knowledgeplaza.profiler.engine.model.Agent2User@5366ef, Id=1001 / nl.knowledgeplaza.profiler.engine.model.Agent2User@5366ef, Id=1001 / true
WasRemoved = true
agent2user list size after remove = 1
>>nl.knowledgeplaza.profiler.engine.model.Agent2User@5366ef, Id=1001 / nl.knowledgeplaza.profiler.engine.model.Agent2User@5366ef, Id=1001 / true
Explanation:
1. The method enters and the list reports a size of 1, the objects appear to be equal.
2. The if condition passes, so contains must have returned true.
3. The remove is executed and WasRemoved is true.
4. Then it turns out the list is NOT of size zero and the entity is still present!!!
How can this be?
I tried to reproduce this in a standalone example, but I cannot. This only happens if the entity is returned via a SOAP interface. That doesn't solve my problem though.
Tom
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03399 seconds