I have a class Country mapped as follows:
<class name="Country" table="tbl_country" lazy="false">
        <id name="ID" column="country_id">
            <generator class="identity"></generator>
        </id>
        <property name="Name" column="country_name"></property>
        <set name="States" inverse="true" outer-join="true">
            <key column="country_id_FK"></key>
            <one-to-many class="State" />
        </set>
    </class>

and a State Country mapped as follows using FluentNH (yes I am mixing
2 mapping approaches pending migration):
public class StateMap : ClassMap<State>
    {
        public StateMap()
        {
            Not.LazyLoad();
            Table("tbl_state");
            Id(x => x.ID).Column("state_id");
            Map(x => x.Name).Column("state_name");
            References(x => x.Country).Column("country_id_FK");
            HasMany(x =>
x.Regions).KeyColumn("state_id_FK").Inverse();
        }
    }


I am intentionally avoiding lazy loading, so I expect my Country to
have its States loaded when I do this HQL:
session.CreateQuery("from Country c order by c.Name
").List<Country>();
but when I access the Country.States collection I get a
LazyInitializationException, why?
I can get the States loaded when I use session.Get<Country>(1) for
example (Get fetches differently from HQL, also why)
I also can make it work in HQL by using something like:
session.CreateQuery("from Country c left join fetch c.States order by
c.Name ").List<Country>();

Can anyone explain the behavior?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to