收录日期:2019/05/20 13:37:54 时间:2009-07-29 17:57:43 标签:nhibernate

I Have one-to-one relation in my NHibernate mapping:

<many-to-one name="PersonProfile" not-null="true"
    class="PersonProfile" column="profile" cascade="all" lazy="proxy"/>
...
<one-to-one name="Owner" class="Person" property-ref="PersonProfile" 
    constrained="true" lazy="proxy"/>

PersonProfile class have batch-size attribute set. When user.PersonProfile property is hit batch load triggers. But then, when Owner property is loaded it loads from database. Why?

Because one-to-one relations can not be lazy loaded (in some circumstances).

See this fine explanation: http://stackoverflow.com/questions/389026/nhibernate-how-to-enable-lazy-loading-on-one-to-one-mapping