Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » remove not removing
remove not removing [message #389736] Thu, 25 June 2009 10:06 Go to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
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
Re: remove not removing [message #389742 is a reply to message #389736] Thu, 25 June 2009 14:11 Go to previous messageGo to next message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
Don't ask me how, but the problem is gone. The illustrated problem occurred over a longer period of time (hours), then I stopped work on it and started something else, and now it's gone.

Sometimes computers simply baffle me. Next.

Tom
Re: remove not removing [message #389743 is a reply to message #389736] Thu, 25 June 2009 14:12 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

My guess is you have two copies of the source object. Try printing the
source object as well.

i.e.
Agent->Agent2User->Agent'

Seems like you corrupted your object with multiple copies, you may be
missing a merge somewhere.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: remove not removing [message #389744 is a reply to message #389743] Thu, 25 June 2009 14:15 Go to previous message
Tom Eugelink is currently offline Tom EugelinkFriend
Messages: 817
Registered: July 2009
Senior Member
> My guess is you have two copies of the source object. Try printing the
> source object as well.
>
> i.e.
> Agent->Agent2User->Agent'
>
> Seems like you corrupted your object with multiple copies, you may be
> missing a merge somewhere.

Aside from that my problem is gone now; the debug output printed the memory address of the object (@5366ef) and both were identical. The contains and remove were done on the same list in the same method. IF it passed "contains" then it should have been removed. Right?

But alas, it is gone.

Tom
Previous Topic:CascadeType=ALL does not result in ON DELETE CASCADE?
Next Topic:Generics and Eclipselink
Goto Forum:
  


Current Time: Thu Apr 25 18:14:40 GMT 2024

Powered by FUDForum. Page generated in 0.02847 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top