<id name="Id"  column="ChargeId" unsaved-value="0">
      <generator class="NHibernate.Id.TableGenerator">
        <param name="table">Discost_NextId</param>
        <param name="column">NextId</param>
      </generator>
    </id>
    <property name="AddedOn" type="string"  length="30" />    <set name="ClinicalChargeRations"
     table="Discost_ClinicalChargeRation"
          lazy="true"
     cascade="all">
      <key column="ChargeId"></key>
      <composite-element class="Vitas.Shared.Discost.ClinicalChargeRation, Shared.Discost">        <property name="ItemId" type="Int32" column="ItemId"  not-null="true"/>
        <property name="ItemName" type="string" column="ItemName" length="80" not-null="true"/>
        <property name="ItemSpec" type="string" column="ItemSpec" length="40" />
        <property name="UnitName" type="string" column="UnitName" length="40" />
        <property name="Amount" type="double">
          <column name="Amount" sql-type="numeric(10,4)" not-null="true"/>
        </property>      </composite-element>
    </set>    <set name="ClinicalDrugRations"
table="Discost_ClinicalDrugRation"
     lazy="true"
cascade="all">
      <key column="ChargeId"></key>
      <composite-element class="Vitas.Shared.Discost.ClinicalDrugRation, Shared.Discost">
        <property name="ItemId" type="Int32" column="ItemId"  not-null="true"/>
        <property name="ItemName" type="string" column="ItemName" length="80" not-null="true"/>
        <property name="ItemSpec" type="string" column="ItemSpec" length="40" />
        <property name="UnitName" type="string" column="UnitName" length="40" />
        <property name="Amount" type="double">
          <column name="Amount" sql-type="numeric(10,4)" not-null="true"/>
        </property>      </composite-element>
    </set>
这样并排着写两个set的集合对不对?我现在遇到问题,在根据chargeid查找相关的集合的时候,在ClinicalChargeRation表中会自动插入新数据。并没写save和update语句。

解决方案 »

  1.   

    cascade="all" ---〉cascade="no"http://www.cnblogs.com/renrenqq/archive/2006/08/16/478198.html 你自己看吧
      

  2.   

    cascade="no"
    那这样还能级联删除吗?
      

  3.   

    现在的疑问是,为什么只会在Discost_ClinicalChargeRation这张表发生错误,而Discost_ClinicalDrugRation表不会有错误呢?
    还有就是在集合表Discost_ClinicalChargeRation只有一条数据时候也不会有问题。
    我在数据库中,把ChargeId,Itemid设成复合主键,在查看数据时候通过约束使数据不能被重复添加,但这时候因为查看时的自动添加数据会产生约束出错,使数据也不能正常查出来。
      

  4.   

    没办法吗?看看这个映射,本身有没有问题?这样两个set有没问题?
    还有就是持久化的问题,这个自动的更新肯定是因为在内存中因为什么原因把集合改变了,hibernate的脏数据检测后,就自动更新数据库。
    有没有办法不让自动更新?我现在的操作仅仅是一个find。