Hello, community
What do you think about assertion in subject?
so, look at this
Code:
class A {
@ManyToMany
Set<B> bes=...;
}
class B {
@ManyToMany(mappedBy="bes")
Collection<A> aes=...;
void addAssociation(A newbie){
// everything is clear. and works well
....
}
void removeAssociation(A associated){
assert aes.remove(associated); // works fine
assert a.bes.remove(this); // doesn't works !!!
}
}
if you try to run simple "exploit", you would be unhappy
Code:
void foo(){
A a = .... // gets poxy from session
B b = a.iterator().next(); // gets proxy of associated entity by association
b.removeAssociation(a); // we'll got a fail
}
Of course, I know the cause:
1. method call would be delegated to entity (target) by proxy
2. so, "this" in method body means entity (target) not a proxy
3. We can't find entity in collection of proxies, in spite of we have proxy with such ID there
What do you think about this issue?