Nhibernate- Lazy Load initialization fail
i am facing a problem.I have a 2 Model projects and ProjectChangeRequest. one project have multiple change request.
Now on Nhibernate mapping xml file i have taken class like this
in Project
<class name="Project" table="project" lazy="false">
<id name="ProjectID" column="ProjectID">
<generator class="native" />
</id>
<property name="ProjectName" column="ProjectName" not-null="false" />
<many-to-one name="Client" class="Client" column="ClientID" unique="true" />
<bag name="ChangeRequest" generic="true" inverse="true" cascade="all" lazy="false">
<key column="ProjectID" />
<one-to-many class="ProjectChangeRequest" />
</bag>
</class>
and in Project Change Request
<!--ProjectChangeReques-->
<class name="ProjectChangeRequest" table="projectchangerequest" lazy="false">
<id name="ProjectChangeRequesID" colu开发者_JAVA技巧mn="ProjectChangeRequesID" >
<generator class="native"/>
</id>
<many-to-one name="Project" class="Project" column="ProjectID" unique="true"/>
<property name="ProjectChangeRequestDetail" column="ProjectChangeRequestDetail" not-null="false" />
</class>
When there is no data on projectchangerequest table then i am getting error that "Unknown column 'changerequ0_.ProjectChangeRequesID' in 'field list'"
"base {NHibernate.HibernateException} = {"Failed to lazily initialize a collection"}"
Please help me to solve this problem.
you could try setting the not-found attribute of your one-to-many association to "ignore", maybe this solves your problem.
e.g.
<bag name="ChangeRequest" generic="true" inverse="true" cascade="all" lazy="false">
<key column="ProjectID" />
<one-to-many not-found="ignore" class="ProjectChangeRequest" />
</bag>
精彩评论