Calling a method on a proxy object that returns "this" will incorrectly return the proxy instead of the "real object" that you would expect.
This results in a ClassCastException...
The class JavassistLazyInitializer incorrectly returns the proxy when the return object equals the proxy. This is incorrect (too simple), it should be the real object (in most cases).
++ Detail explanation with example:
https://forum.hibernate.org/viewtopic.php?f=1&t=1024879
Proposal:
Please replace line 200 in JavassistLazyInitializer:
return returnValue == target ? proxy : returnValue;
by:
return returnValue == target && returnValue.getClass().isInstance(proxy) ? proxy : returnValue;
I tested this (not running all Hibernate unit tests), and seem to work fine.
Please apply the change in 4.1.9.
|