Hibernate version: 3.0b4, 3.0rc1
I'm trying to understand how the CGLIB proxies work since I'm having issues with collections and lazily initialised objects.
Having a look at the
intercept() method, I can see that the
invoke() method of the
superclass is called and when it returns INVOKE_IMPLEMENTATION, the method is then invoked on the actual (target) object, not the proxy, which
is to be expectd. However, if the one of the arguments is the the proxy instance itself, it does not get changed to the target object. So, in the
following example pseudocode which invokes the equals method on an instance of a class that overrides
equals()
Code:
PeristentObject p = getPersistentInstance(); // some method which returns a proxy
PeristentObject p2 = p;
boolean eq = p.equals(p2); // or p.equals(p) for that matter
the PersistentObject method is called on the target of
p (
p.target), but is being passed
p as an argument. After the call,
eq is false.
This is where my confusion begins: the argument
p, which is an instance of an enhanced PersistentObject has whatever fields PersistentObject has,
as well as a
target member which is the real object. The fields in the proxy instance, however, do not seem to be initialised and so, in the
method call above, the two objects are not deemed equal, which I think is the wrong result.
My question is then: should the
intercept() method implementation check for this case and replace the argument with the target object? perhaps at least for the
equals()
method since it is already treated as a special case?