Hi,
I'm having weird issues trying to use fetch="join" on the properties of more than one subclass of my hibernate mapping file.
First, the situation: I have a constellation of one-to-many tables related by foreign key to a single parent table. The parent table defines the superclass, then overlapping subsets of the related tables define the subclasses. So subclass A will have sets of type (X, Y, and Z) and subclass B will have sets of type (X, V, and W) .
The Hibernate Mapping file looks like this:
Code:
<hibernate-mapping>
<class name="ParentClass" table="SCHEMA.BASE" polymorphism="implicit">
<discriminator column="DISC_COLUMN" type="string" insert="false"/>
<...parent properties...>
<subclass name="A" discriminator-value="DISC_A">
<set name="prop_x" fetch="join">
<key column="BASE_ID_FK" />
<one-to-many class="X" />
</set>
<set name="prop_y" fetch="join">
<key column="BASE_ID_FK" />
<one-to-many class="Y" />
</set>
<set name="prop_z" fetch="join">
<key column="BASE_ID_FK" />
<one-to-many class="Z" />
</set>
</subclass>
<subclass name="B" discriminator-value="DISC_B">
<set name="prop_x" fetch="join">
<key column="BASE_ID_FK" />
<one-to-many class="X" />
</set>
<set name="prop_v" fetch="join">
<key column="BASE_ID_FK" />
<one-to-many class="V" />
</set>
<set name="prop_w" fetch="join">
<key column="BASE_ID_FK" />
<one-to-many class="W" />
</set>
</subclass>
</class>
The Criteria query used looks like this:
Code:
Criteria criteria = hSession.createCriteria(ParentClass.class);
.addOrder(Order.asc("order_column"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
Now, when I execute that Criteria (in order to get both As and Bs back), the select statement output left outer joins V, W, X, Y, and Z (just like you'd think it would). Attempts to access a returned object of type A's properties are successful without Lazy loading (as I want it to be), but any attempt to access an object of type B's properties results in them being lazy loaded, even though they should be available.
But it gets weirder! Which subclass has immediate access to the SELECTed information is position dependent! If I swap subclass B above subclass A in the mapping file, then
it works fine, while class A does the lazy loading.
I've also tried moving class A out to an external mapping file, but the behavior is the same, it still insists on lazy loading its properties.
If anybody has seen this before and has a solution, or even has a suggestion about what I should try next, I would be extremely grateful. If I can provide any further information please don't hesitate to let me know. It seems to me that any behavior that treats one sibling differently from another is not working as designed.
Thanks for your time,
matt