I'm having problems getting a n-to-one relationship to work via lazy activation. Basically, I have a User class which has a <many-to-one> property to an Address.
The mapping def for the relationship in User looks like:
Code:
<many-to-one name="UserAddress"
class="NHibernateTestModel.Address, NhibernateTestModel"
column="addID" cascade="all"/>
The Address class mapping contains the lazy="true" attribute:
Code:
<class name="NHibernateTestModel.Address, NhibernateTestModel" table="Address" lazy="true">
<id name="ID" column="addID" type="Int32" unsaved-value="0">
<generator class="assigned" />
</id>
<property name="Address1" column="Address1" type="String" length="255"/>
<property name="City" column="City" type="String" length="255"/>
...
</class>
In the test application, I access the address like this:
Code:
User user = (User)session.Load(typeof(User), "john");
Address addr = user.UserAddress;
string street = addr.Address1;
The returned address object ("addr") is an instance of CProxyTypeAddress_ISerializable_INHibernateProxy2. When invoking the property accessor Address1, no access to the database is ever done to fetch the Address instance, and the value null is returned. If I remove the "lazy=true" line to the Address class mapping, the address object is fetched with the user but everything is returned correctly.
Any idea what I'm doing wrong here?
thanks,
--john