I have a root persistent class with a default implementation of the equals(...) method.
It assumes that two persistent objects are equals if:
- they have the same identifier value
- AND share the same class
Code:
public boolean equals(Object obj) {
Persistent other = (Persistent) obj;
boolean sameId = this.getId().equals( other.getId() );
boolean sameClazz = this.getClass().equals( other.getClass() );
return (sameId && sameClazz);
}
Problem: when working with proxies, the other object to compare with (obj) may sometimes be of a different "physical " class (e.g. a cglib
class) although they share the same "logical" class...
Therefore, equals return false :-(
Any idea/hint/recommendation for having a good implementation which works in all cases ?
Thanks in advance,
Bernard.