Hello!
I encountered an issue with collection (bag) mappings in parent class, i.e:
Code:
<class name="Parent" table="Parent">
<id name="ID" column="ID" unsaved-value="0">
<generator class="identity" />
</id>
<bag name="FooBag" table="FooBag" inverse="true" cascade="all">
<key column="ParentID" />
<one-to-many class="Foo" />
</bag>
<joined-subclass name="SubClass" table="SubClass">
<key column="ID" />
<!-- ... -->
</joined-subclass>
</class>
<class name="Foo" table="Foo">
<id name="ID" column="ID" unsaved-value="0">
<generator class="identity" />
</id>
<many-to-one name="Parent" column="ParentID" class="Parent" not-null="true" />
<bag name="BarBag" table="BarBag" inverse="true" cascade="all">
<key column="FooID" />
<one-to-many class="Bar" />
</bag>
</class>
When I load the SubClass item and start browsing through the FooBag,
it contains as many items as there are lines associated to it in the BarBag table. I.e
Code:
[Parent]-1-----10-[FooBag]-1-----10-[BarBag]
SubClasses list actually contains 100x FooBag each having 10x BarBag
items. Correct result would've been SubClass having 10x FooBag with
each having 10x BarBag. If one cut+pastes the <bag name="FooBag" ...>
from the Parent to SubClass, the implementation works correctly.
I've tried to re-implement equals/hashcode methods, but in vain. So, is
this a known issue, or am I just doing something horribly wrong? :)
Putting the ugliness of workarouds aside, one solution to the problem
above is to cut+paste the <bag name="FooBag" ...> to every subclass
definition.
- D -