我正在尝试保存一对多映射,nHibernate会将此错误抛给我,因为它为ordPsiPt
表的两个条目分配了相同的ID。
我环顾四周,使用Session.merge()
也无效。
以下是类的映射:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2">
<class name="ordPsiPt" table="ord_psi_pt" lazy="true" >
<id name="idOrdPastaIT">
<generator class="identity" />
</id>
<many-to-one lazy="false" name="ordPsi">
<column name="idOrdPastaI" sql-type="int(11)" not-null="true" />
</many-to-one>
<many-to-one lazy="false" name="pastaTopping">
<column name="idPastaT" sql-type="int(11)" not-null="true" />
</many-to-one>
<property name="amount">
<column name="Amount" sql-type="varchar(50)" not-null="true" />
</property>
</class>
</hibernate-mapping>
order_psi:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2">
<class name="ordPsi" table="ord_psi" lazy="true" >
<id name="idOrdPastaI">
<generator class="identity" />
</id>
<many-to-one lazy="false" name="order">
<column name="idOrder" sql-type="int(11)" not-null="true" />
</many-to-one>
<many-to-one lazy="false" name="pastaIndividual" class="pastaIndividual">
<column name="idPastaI" sql-type="int(11)" not-null="false" />
</many-to-one>
<property name="obs">
<column name="obs" sql-type="varchar(50)" not-null="false" />
</property>
<property name="price">
<column name="price" sql-type="decimal(8,4)" not-null="true" />
</property>
<bag name="ordPsiPt" table="ordPsiPt" cascade="save-update" inverse="true">
<key column="idOrdPastaIT"/>
<one-to-many class="ordPsiPt"/>
</bag>
</class>
</hibernate-mapping>
顺序:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="FrancosPoS" namespace="FrancosPoS.DBMapping" xmlns="urn:nhibernate-mapping-2.2">
<class name="order" table="`order`" lazy="true" >
<id name="idOrder">
<generator class="identity" />
</id>
<property name="price">
<column name="price" sql-type="decimal(8,4)" not-null="true" />
</property>
<property name="cash">
<column name="cash" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="credit">
<column name="credit" sql-type="tinyint(1)" not-null="false" />
</property>
<property name="obs">
<column name="obs" sql-type="varchar(350)" not-null="false" />
</property>
<bag name="orderPsi" table="ordPsi" cascade="all" inverse="true">
<key column="idOrdPastaI"/>
<one-to-many class="ordPsi"/>
</bag>
</class>
</hibernate-mapping>
行李在cs映射上获取IList
。
当我使用订单对象调用SaveOrUpdate()
时,在一个orderPsi中只有两个orderPsiPt(仅作为示例),我收到了有关标识符的错误。
我试图仅为此示例使用conn.Session.Merge(order.orderPsi[0].ordPsiPt[1]);
,但也没有成功。
如果有帮助,这里有来自两个ordPsiPt的手表: http://db.tt/2wNWldyd
我也试着看看这个:
http://ayende.com/blog/4282/nhibernate-cross-session-operations