views:

180

answers:

1

Hello All

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" column="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.

A: 

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>
Joachim Kerschbaumer
sry @@Joachim.. still getting same error
Pankaj
is your Column name really "ProjectChangeRequesID" and not "ProjectChangeRequestID" ? missing "t" ?
Joachim Kerschbaumer
yes you are right. that was the problem... Thanks
Pankaj