当我访问child时,NHibernate强制UPDATE语句

时间:2009-10-31 21:17:16

标签: nhibernate

我有父母与孩子的关系。

我的问题是,当我访问子对象,然后刷新会话时,NHibernate会自动更新具有相同值(无差异)的子对象。

这将发布孩子的更新:

Response.Write(Profile.ProfilePicture.Filename);
_session.Flush();

谁能明白为什么会这样?我当然不想在这种情况下更新孩子。

这是我的hibernate映射:

父:

<class name="Business.Domain.Profile, Business" table="Profiles">  
    <id name="Id" type="int">
      <generator class="native" />
    </id>
    <property name="Username" type="string" length="100" />
    <property name="Password" type="string" length="200" />
    <property name="Email" type="string" length="150" />
    <property name="CreatedDate" generated="insert" />
    <property name="LastLoginDate" />
    <property name="LastActivityDate" />
    <property name="Firstname" type="string" length="50" />
    <property name="Lastname" type="string" length="50" />
    <property name="Fullname" formula="Firstname + ' ' + Lastname" />
    <property name="Gender" not-null="true" type="int" />
    <property name="Description" not-null="false" type="string" />

    <many-to-one
      name="ProfilePicture" 
      column="ProfilePictureId" 
      class="Business.Domain.Picture, Business" />

    <set name="Pictures" generic="true" inverse="true" cascade="all-delete-orphan">
      <key column="ProfileId" />
      <one-to-many class="Business.Domain.Picture, Business"/>
    </set>
  </class>

子:

  <class name="Business.Domain.Picture, Avando.Business" table="Pictures">
    <id name="Id" type="int">
      <generator class="native" />
    </id>
    <property name="Filename" type="string" />
    <property name="CreatedDate" type="DateTime" generated="insert" />

    <many-to-one
      name="Profile"
      column="ProfileId"
      class="Business.Domain.Profile, Business"
      not-null="true" />    
  </class>

1 个答案:

答案 0 :(得分:0)

我把它排除在外。

由于属性而发生更新:

实际上是一个枚举:)