Hello All,
After some more investigation from our group, we have a better understanding of why our solution causes problems.
So, the situation was that
hibernateProxyObject.equals(hibernateProxyObject) returns false, even though the equality method is implemented as ==.
Apparantly, upon invocation of a method in a hibernate session, Hibernate checks whether the equals method is overriden: if so, the proxy on which the equality method is invoked is resolved (see JavassistLazyInitializer line 191/BasicLazyInitializer line 95).
Code:
if ( !overridesEquals && "equals".equals(methodName) ) {
return args[0]==proxy ? Boolean.TRUE : Boolean.FALSE;
}
Therefore, what is actually invoked is:
hibernateResolvedObject.equals(hibernateProxyObject), evidently returning false. If you just do not override the equals method, the proxy is not swapped out and the referencecomparison passes. So although our equality implementation is identical to the reference compare, we still get different results. We can not work around this except by not using the parentclass which overrides the equality operator in the first place.
I believe, however, that the fact that hibernate swaps out the callee for the real object, and not the same proxy in the method parameter list is a bug. If you have resolved the proxy anyway, you might as well change the proxy instance in the parameter list to the real thing as well. There seems to be no disadvantage to this, and will fix all problems with == in method implementations and proxies. If this is not a good idea, again I would really like to hear why: I'm always willing to learn :)
Thanks,
Yves