Code:
<hibernate-mapping package="sandbox">
<class name="person" table="PERSON">
<id name="id" />
<property name="name" />
<joined-subclass name="child" table="CHILD">
<key column="id" />
<bag name="certificates" table="CERTIFICATES" lazy="false"
fetch="subselect" cascade="all">
<key column="id" />
<composite-element class="Certificate" >
<property name="board" />
<property name="grade" />
</composite-element>
</bag>
</joined-subclass>
</class>
</hibernate-mapping>
If my child table has 10 rows. Hibernate does 11 queries. 1 to get all the children and then 1 per child to find certificates for each child.
This does not scale very well, is there a way to use join. I have tried using different combinations of cascade/fetch/lazy etc, but have not managed to reduce the queries?
Any help is much appreciated
Thanks
Chris