Using the mappings below (which I've cut down for clarity), and executing the query specified, I find that NHibernate is generating a single select on the Clients table, as I'd expect, but then is hydrating each of the freightpayers in turn (ie, a query for each) as well. I tried adding the lazy="proxy" attribute to see if that would make a difference, but it didn't help. Can someone tell me what I'm doing wrong?
Hibernate version:
1.2GA
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Domain" assembly="Saturn.DAO">
<class name="Saturn.DAO.Domain.Client, Saturn.DAO" table="Clients" >
<composite-id name="ID" class="Saturn.DAO.Types.DBKey">
<key-property name="Prefix"/>
<key-property name="ID"/>
</composite-id>
<one-to-one name="Freightpayer" lazy="proxy" class="Saturn.DAO.Domain.Freightpayer, Saturn.DAO" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Domain" assembly="Saturn.DAO">
<class name="Saturn.DAO.Domain.Freightpayer, Saturn.DAO" table="FreightPayers">
<composite-id name="ID" class="Saturn.DAO.Types.DBKey">
<key-property name="Prefix"/>
<key-property name="ID"/>
</composite-id>
<one-to-one name="Client" class="Saturn.DAO.Domain.Client, Saturn.DAO" constrained="true" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
session.CreateQuery("FROM Client C ORDER BY C.Name").List(Of Domain.Client)()
Name and version of the database you are using:
MS SQL Server 2005