Hibernate 3.0.5 & 3.1rc2
Mapping
<class name="ProductDefinition">
...
<set name="contractProducts" inverse="true">
<key column="pde_id"/>
<one-to-many class="ContractProduct"/>
</set>
<set name="specialProducts" inverse="true">
<key column="pde_id"/>
<one-to-many class="SpecialProduct"/>
</set>
</class>
// Hierarchy to single table mapping:
<class name="ProductComponent">
...
<discriminator column="class" type="java.lang.String" length="2"/>
<subclass name="ContractProduct" discriminator-value="CP">
<many-to-one name="productDefinition"
class="ProductDefinition"
column="pde_id"/>
</subclass>
<subclass name="SpecialProduct" discriminator-value="SP">
<many-to-one name="productDefinition"
class="com.tpgmail.spp.model.ProductDefinition"
column="pde_id"/>
</subclass>
</class>
If I retrieve ProductDefinition.contractProducts & ProductDefinition.specialProducts I get a WrongClassException because hibernate does not use the discriminator value retrieving these collections.
The result of this is that both collection retrieval queries return all rows that map to the given parent and there is no discrimination for the correct type.
Are there any workarounds?
These are the generated OneToManyLoader statements:
14:43:10:621 DEBUG (OneToManyLoader.java:106) Static select for one-to-many com.tpgmail.spp.model.ProductDefinition.specialProducts: select specialpro0_.pde_id as pde12_1_, specialpro0_.id as id1_, specialpro0_.id as id0_, specialpro0_.tcn as tcn19_0_, specialpro0_.last_change as last4_19_0_, specialpro0_.last_group_change as last5_19_0_, specialpro0_.dov_id as dov6_19_0_, specialpro0_.pco_id as pco7_19_0_, specialpro0_.sequence as sequence19_0_, specialpro0_.number_of_outlets as number10_19_0_, specialpro0_.pde_id as pde12_19_0_ from spp_product_component specialpro0_ where specialpro0_.pde_id=?
14:43:10:591 DEBUG (OneToManyLoader.java:106) Static select for one-to-many com.tpgmail.spp.model.ProductDefinition.contractProducts: select contractpr0_.pde_id as pde12_1_, contractpr0_.id as id1_, contractpr0_.id as id0_, contractpr0_.tcn as tcn19_0_, contractpr0_.last_change as last4_19_0_, contractpr0_.last_group_change as last5_19_0_, contractpr0_.dov_id as dov6_19_0_, contractpr0_.pco_id as pco7_19_0_, contractpr0_.sequence as sequence19_0_, contractpr0_.number_of_outlets as number10_19_0_, contractpr0_.pde_id as pde12_19_0_, contractpr0_.con_id as con13_19_0_ from spp_product_component contractpr0_ where contractpr0_.pde_id=?
|