0

我在 Invoice 和 InvoiceDetail 之间创建了如下所示的映射。尝试更新发票时,我也注意到用户的更新语句。当我们设置了 cascade =“none” 时,为什么要更新“用户”?

  <class name="Invoice" table="invoice" lazy="false">
    <id name="InvoiceID" column="InvoiceID" type="int">
      <generator class="native"/>
    </id>
    <property name="InvoiceDate" column="InvoiceDate" type="DateTime"></property>
    <property name="InvoiceNo" column="InvoiceNo" type="String"></property>
    <property name="TotalAmount" column="TotalAmount" type="Decimal"></property>
    <many-to-one class=User" name="User" column="UserID" cascade ="none" />
    <component name="InvoiceDetailList">
      <bag name="items" table="invoicedetail" lazy="false" cascade="all-delete-orphan" access="field" inverse="true" >
        <key column="InvoiceID" on-delete="cascade" />
        <one-to-many class="InvoiceDetail"/>
      </bag>
    </component>    
  </class>

  <class name="InvoiceDetail" table="invoicedetail" lazy="false">
    <id name="InvoiceDetailID" column="InvoiceDetailID" type="int">
      <generator class="native"/>
    </id>    
    <property name="ProductID" column="EntityID" type="int"></property>
    <property name="Quantity" column="Quantity" type="int"></property>
    <property name="TotalPrice" column="TotalPrice" type="Decimal"></property>
    <many-to-one class="Invoice" name="Invoice" column="InvoiceID" not-null="true"/>
  </class>

谢谢

阿努拉格

4

1 回答 1

0

Are you making ANY changes to the user object? Default behaviour in NHibernate is to Automatically flush & commit changes at the end of session, so if you have made changes to the user object those changes will be committed at the end of the session.

session.FlushMode = FlushMode.Never;

will prevent this behaviour and ensure that changes are only saved when the entity is explicitly updated, either directly or via association.

于 2009-11-07T19:32:34.393 回答