在它提交翻译时,我遇到了一些错误。下方给出了错误
对象引用了一个未保存的瞬态实例-在刷新前保存瞬态实例,或者将该属性的级联操作设置为使其自动保存的操作。
我已经为TBASubType 创建了一个.hbm.xml文件
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="M3.Entities" assembly="M3.Entities" xmlns="urn:nhibernate-mapping-2.2">
<class name="TBASubType" table="tBASubType" schema="dbo">
<id name="FSubTypeID" type="Guid">
<generator class="assigned" />
</id> <version name="FTimestamp" generated="always" unsaved-value="null" type="BinaryBlob"> <column name="FTimestamp" not-null="true" sql-type="timestamp"/> </version>
<property name="FType" type="Int32" precision="10" not-null="true" />
<property name="FName" type="String" length="50" not-null="true" />
<property name="FActive" type="Boolean" not-null="true" />
<many-to-one name="TSCEnterprise" class="TSCEnterprise" column="fEnterpriseID" not-null="true" />
<set name="TBADepositMasters" table="tBADepositMaster" inverse="true" cascade="all">
<key column="fSubTypeID" />
<one-to-many class="TBADepositMaster" />
</set>
</class>
</hibernate-mapping>
如何解决此错误?
我认为您正在使用hbm.xml文件来维护表之间的关系。如果您使用的是"多对一"关系,则意味着您正在将父子关系与表关联起来。您应该使用insert="false"update="false),如下所示:
<many-to-one
name="TSCEnterprise" class="TSCEnterprise"
column="fEnterpriseID" not-null="true"
insert="false" update="false" />