Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 1.2.0.GA
Name and version of the database you are using: MS Sql Server 2000
Consider the Parent, Child relationship using this mapping:
Code:
<class name="Parent" table="parents">
<id name="id" column="id" type="int">
<generator class="identity" />
</id>
<property name="firstName" column="firstName" />
<property name="lastName" column="lastName" />
<bag name="children">
<key column="parentId"/>
<one-to-many class="Child"/>
</bag>
</class>
<class name="Child" table="children">
<id name="id" column="id" type="int">
<generator class="identity" />
</id>
<property name="firstName" column="firstName" />
<property name="parentId" column="parentId" />
<many-to-one name="parent" class="Parent" column="parentId" fetch="join" lazy="false"/>
</class>
If I retrieve a list of Children, why does it create a SELECT for every Parent when I use the fetch="join" attribute? Or do I miss-understand the "fetch" attribute? If so, is there a better way I should be doing this?
Ulitmate goal: I want to display all the children's names (thousands):
Code:
child.FirstName + " " + child.Parent.LastName;
or maybe???:
Code:
child.FirstName + " " + child.ParentLastName;
and have the initial list of children created using a join instead of a select for each child's parent.