Consider objects like these:
public partial class Record
{
public int RecordID {get; set;}
public DateTime? Created { get; set; }
public int CreatorUserUserObjectNDX { get; set; }
public UserObject Creator { get; set; }
...
}
and
public partial class UserObject
{
public virtual int ID {get; set;}
public virtual string Name {get; set;}
}
and their mappings like:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="..." namespace="..." assembly="...">
<class name="Record" table="records" lazy="false" schema="..">
<id name="RecordID" column="ndx">
<generator class="native" />
</id>
<property name="Created" column="created" />
<property name="CreatorUserUserObjectNDX" column="creator_user_user_object_ndx" />
<many-to-one name="Creator" column="creator_user_user_object_ndx" lazy="proxy"/>
</class>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="..." namespace="..." assembly="...">
<class name="UserObject" table="user_objects" lazy="false">
<id name="NDX" column="ndx">
<generator class="native" />
</id>
<property name="Name" column="name" />
</class>
They are kept simple intentionally here, in real they're more heavy with one-to-many collections etc, but these work, so they're not the point here.
The problem I ran into is, when I use definitions & mappings like these, and do a simple
var results = session.QueryOver<Record>()
.List();
NHibernate does NOT create a proxy for the creator property, it just uses left outer joins in the executed SQL statement and inserts a UserObject directly.
When I change lazy='false' to lazy='true' within the mapping for UserObject it works, proxy is created and the executed SQL has no outer joins.
So, is it strictly necessary to set lazy='true' for all classes, that may be a reference anywhere? I thought I could use set it to false per default for all mappings and set lazy='proxy' in the many-to-one definition, when needed.
I use NHibernate 3.2, so no config about proxyfactory. What am I missing here?