If have an entity A with a bidirectional one-or-zero-to-one mapping with entity B.
The mapping is as follows:
<class name="EntityA" table="TABLE_A" mutable="true" lazy="true">
<id name="idA" type="long" column="pk_a" unsaved-value="null">
<generator class="sequence">
<param name="sequence">pk_a_seq</param>
</generator>
</id>
<one-to-one name="propertyB" class="EntityB" property-ref="propertyA" constrained="true" outer-join="false"/>
</class>
and
<class name="EntityB" table="TABLE_B" mutable="true" lazy="true">
<id name="idB" type="long" column="pk_b" unsaved-value="null">
<generator class="sequence">
<param name="sequence">pk_b_seq</param>
</generator>
</id>
<many-to-one name="propertyA" class="EntityA" not-null="true" unique="true" lazy="proxy" column="fk_a"/>
</class>
When I do an hql query (or rather, a named hql query) for EntityA, hibernate eagerly loads EntityA#propertyB with a separate select statement.
My problem with that is if my hql returns 1000 EntityA's (with all having their own respective EntityB's), hibernate will do n+1 queries (1st query would be for EntityA returning 1000 results, while the n queries would be coming from the EntityA#propertyB select lazy loading).
However, I do not need those EntityA#propertyB's that's why I want to lazy load them instead (without having hibernate use a separate sql query).
Is that possible? And if it is, how do I do that?
Thanks, Franz