Issue Type: Bug Bug
Affects Versions: 4.2.1, 3.6.10
Assignee: Unassigned
Attachments: hibernate-extendsqueue-test.zip
Components: core
Created: 28/Apr/13 11:55 PM
Description:

On building a session factory the HbmBinder.bindRoot() delays subclass entity mapping creation, if one the referenced superclasses has not been loaded, yet.

If one mapping file contains mappings for multiple subclasses, which reference still not loaded superclasses, then there occurs a bug because of the way the queuing works for delayed loading. For each missing superclass there is created one queue entry containing ALL the entities of the mapping file.

Consider the following example:

Subclasses.hbm.xml
hibernate-mapping>
<hibernate-mapping>
  <subclass name="de.di.hibernate.tests.Subclass1" extends="de.di.hibernate.tests.RootClass1">
    <property name="age" />
  </subclass>

  <subclass name="de.di.hibernate.tests.Subclass2" extends="de.di.hibernate.tests.RootClass2">
    <property name="age" />
  </subclass>
</hibernate-mapping>

There are referenced two superclasses RootClass1 and RootClass2. If they both are not loaded yet the created queue entries are:

RootClass1 -> [Subclass1, Subclass2]
RootClass2 -> [Subclass1, Subclass2]

Later on, when the queued entries are iterated through, the subclasses are going to be mapped twice. This leads to a DuplicateMappingException.

Workaround 1: define mapping files which contain at most one subclass mapping.

Workaround 2: assure that superclass mappings are always loaded before subclass mappings.

I think this a bug, as generally it is allowed to define more than one subclass mapping per mapping file. The order in which mapping files are loaded is free, as the HbmBinder contains a treatment for this case (as mentioned in this bug ticket).

Test case attached.

Environment: JDK 1.6
Project: Hibernate ORM
Priority: Major Major
Reporter: Stefan Fromm
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