Ed Bras created Bug HHH-7845
Issue Type: Bug Bug
Affects Versions: 4.1.8
Assignee: Unassigned
Components: core
Created: 04/Dec/12 2:13 AM
Description:

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.

Environment: Windows 7, 64 bit, Linux CentOs
Project: Hibernate ORM
Labels: hibernate
Priority: Major Major
Reporter: Ed Bras
Original Estimate: 1h
Remaining Estimate: 1h
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira