I have a two tables, basically a parent table and a child table. I want the parent object to contain a set of child ids as opposed to references to the child objects themselves. I feel I set this up propertly in the hbm.xml file (see below). However, when I access all the parent objects I see that hibernate executes a select statement for every parent row, instead of a single join! Can this be right?
Code:
<hibernate-mapping>
<class name="eg.Parent" table="PARENT">
<id name="id" column="ParentID" type="int">
<generator class="identity"/>
</id>
<set name="childIDs" table="CHILD" cascade="all" lazy="false">
<key column="ParentID"/>
<element column="ChildID" type="int"/>
</set>
</class>
</hibernate-mapping>
In my DAO object I execute: session.find(from Parent);
The resuling sql is basically:
select * from PARENT
select * from CHILD where ParentID = ?
select * from CHILD where ParentID = ?
select * from CHILD where ParentID = ?
.
.
I would expect it to be something more like:
select * from Parent p inner join Child c on p.id=c.parentID
Using hibernate 2.1.
Thanks,
Thaddeus