C# – Save the transient instance before flushing or set cascade action for the property to something that would make it autosave

cnhibernate

I am facing some error while it commits translation.The error is given below

Object references an unsaved transient instance – save the transient instance before flushing or set cascade action for the property to something that would make it autosave.

I have created a .hbm.xml file for TBASubType

<?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>

How can I solve this error?

Best Answer

I think you are using hbm.xml file to maintain relationship between tables. If you are using "many to one" relationship that means you are relating Parent to child relationship with a table. You should use insert="false" update="false", like so:

<many-to-one
      name="TSCEnterprise" class="TSCEnterprise"
      column="fEnterpriseID" not-null="true"
      insert="false" update="false" />