Hi,
I've chosen a "Table per subclass, using a discriminator" strategy to map inheritance.
Everything works fine but I have one question about the loading of the subclass properties.
Actually the "lazy" attribute of the "subclass" element seems to have no effects on the sql queries generated, no matter the "fecth" mode ("select" or "join").
The subclass is always loaded with the super class.
For example (using the select fetch mode) the two select queries are always executing simulteanously. Even if I access only a property of the super class. (See below)
What I expect is that Hibernate executes the second query only when a subclass property is needed. This seems to me quite logical as far as some "business" code may only use the super-class.
So how can I "desynchronize" those 2 queries please?
Thanks in advance.
Alexis
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance-tablepersubclass-discriminator
Hibernate version: 3.1.2
Java Class:
Code:
public class Event implements Serializable, Comparable {
private Long id;
private String dataSourceCode;
private Map privateInfoMap = new HashMap();
// ....
}
Mapping documents:Code:
<class name="Event" table="EVENT">
<id name="id" type="long">
<column name="ID"/>
<generator class="hilo"/>
</id>
<discriminator type="string">
<column name="DS_CODE"
length="32"
not-null="true"
index="&prefix;EVENT_IDX0"/>
</discriminator>
<!-- ... -->
</class>
<!-- Subclass -->
<subclass name="Event"
entity-name="STPFC_ENTRY_SPACE"
discriminator-value="STPFC_ENTRY_SPACE"
lazy="true"
extends="Event">
<join table="STPFC_ENTRY_TABLE" fetch="select">
<key column="EVENT_ID"/>
<dynamic-component name="privateInfoMap">
<property name="FC_ID" column="FC_ID" type="long"/>
<property name="foo" column="FOO" type="string"/>
<property name="toto" column="TOTO" type="string"/>
</dynamic-component>
</join>
</subclass>
The generated SQL (show_sql=true):Code:
select event0_.ID as ID0_1_, event0_.DS_CODE as DS2_0_1_ from MSP_EVENT event0_ where event0_.ID=?
select event_1_.FC_ID as FC2_2_, event_1_.FOO as FOO2_, event_1_.TOTO as TOTO2_ from MSP_STPFC_ENTRY_TABLE event_1_ where event_1_.EVENT_ID=?