Hello,
Is there a way to write a HQL or Criteria query to select both the parent and the count of child objects at once? We're aware of the filter to get the child count without initializing the whole collection, but that's N*2 queries.
Hopefully there's a way to do it all at once.
Thanks very much!
Seth
Hibernate version: 2.1.8
Mapping documents:
Code:
<hibernate-mapping>
<class name="org.example.tree.Person" table="person">
<id name="id" unsaved-value="null" type="long">
<generator class="native"/>
</id>
<property name="firstName" column="first_name"/>
<property name="lastName" column="last_name" />
<set lazy="true" batch-size="25" name="children" inverse="true">
<key column="parent_id" />
<one-to-many class="org.example.tree.Person" />
</set>
<many-to-one name="parent" column="parent_id" />
</class>
</hibernate-mapping>
Name and version of the database you are using: MySQL 4.1
[/code]