[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5954) WrongClassException in Single-Table Inheritance

Jeff Crowe (JIRA) noreply at atlassian.com
Tue Feb 22 19:25:08 EST 2011


WrongClassException in Single-Table Inheritance
-----------------------------------------------

                 Key: HHH-5954
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5954
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 3.6.1
         Environment: 3.6.1 Final, MySql 5 & HSQLDB 2
            Reporter: Jeff Crowe


A WrongClassException "loaded object was of wrong class" is randomly encountered in the following situation:

Parent with single-table inheritance A
B extends A
C extends A

Parent with single-table inheritance X
Y extends X
Z extends X

B has field 'x' of type Y
C has field 'x' of type X

During initialization:

* The AbstractEntityPersister for class A is loaded and createLoaders() is called
* JoinWalker.walkEntityTree is invoked for class A
* The persister.getSubclassPropertyType iteration will encounter both fields 'x' from B and C
* If C.x is encountered first, then the base type X is walked and everything works without issues
* If B.x is encountered first, then the subtype Y is walked.
    * When C.x is subsequently encountered, JoinWalker.isDuplicateAssociation will return true for the field and the base type X is not added as an association for A.
    * Later an attempt is made to query for C and a result C.x=Z is returned. A WrongClassException is thrown because Z != expected type Y

This behavior is non-deterministic. The ordering that getSubclassPropertyType iterates is determined by hashtable values and are therefore pseudo-random.

Known workaround:
* Specify (targetEntity=X.class) on B.x
* Alternately avoid duplicate field names on subtypes of a single-table entity hierarchy.

-- 
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