[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2110) Proxied object causes ClassCastException when method returns 'this' in a composite hierarchy

Philip Nightingale (JIRA) noreply at atlassian.com
Wed Sep 27 11:02:24 EDT 2006


Proxied object causes ClassCastException when method returns 'this' in a composite hierarchy
--------------------------------------------------------------------------------------------

         Key: HHH-2110
         URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2110
     Project: Hibernate3
        Type: Bug

  Components: core  
    Versions: 3.0.5    
 Environment: Hibernate 3, any database (test case uses HSQL, issue found using Oracle)
    Reporter: Philip Nightingale
 Attachments: HibernateClassCastExceptionTest.zip

If a proxied object has a method that returns 'this' and the proxy type extends the same base class as the target object and the return type of the method is the target class type then a ClassCastException is thrown.
The error can be tracked down to the method CGLibLazyInitializer::intercept(Object, Method, Object[], MethodProxy).
In this method, if the object returned from the method call on the target object is the same as the target object, then instead of returning the object itself the proxy is returned. This is fine in most cases, but in the special case described, in which the proxy extends a base class that is also extended by the target class, then the CCE occurs.
In the submitted test case I have a simple composite hierarchy with an abstract base type and two concrete subtypes. Either type can contain children, but only one can be the root of the hierarchy (and cannot itslef be a child). There is a many-to-one relationship defined from the sub-type that may be a child to the base class.
The submitted test case is configured to use Hypersonic DB so hsqldb.jar is required on the classpath.
Further details and code snippets from the original code that caused the exception are posted on the Hibernate user forum (topic "ClassCastException with CGLIB Lazy Initialization")

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list