NHibernate WARNING and data is not saved

While I save by calling SaveOrUpdate (), I received this warning and the data is not saved in the database after calling Transaction.Commit ().

NHibernate.Engine.ForeignKeys - It is impossible to determine if [project name] has the assigned identifier [primarykey] temporary or separate; query database. Use Explicit () or Refresh () in a session to prevent this.

I am inserting a new object. On Google search, say that I call Save () instead of SaveOrUpdate (): means Save () is just for insertion.

I search on Google and don’t see much in this. Can someone give me a suggestion on this issue or this warning?

Edit: Here are simulation files with samples -

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly=""
                   namespace="">
    <class name="Customer" table="[dbo].[Customer]" optimistic-lock="none" >
        <id name="CustomerId" column="CustomerId" >
            <generator class="assigned"/>
        </id>
        <property name="Name" column="Name" /> 
        <property name="Age" column="Age" /> 
        <set name="CustomerDetails" cascade="none" inverse="true" fetch="select">
            <key>
                <column name="CustomerId"/>
            </key>
            <one-to-many class="CustomerDetail"/>
        </set> 
        <many-to-one name="MGender" fetch="select" cascade="none">
            <column name="GenderCode"/>
        </many-to-one> 
    </class>
</hibernate-mapping>

<class name="CustomerDetails" table="[dbo].[CustomerDetail]" optimistic-lock="none" >
    <id name="CustomerDetailId" column="CustomerDetailId" >
        <generator class="assigned"/>
    </id>
    <property name="Detail1" column="Detail1" /> 
    <many-to-one name="Customer" fetch="select" cascade="none">
        <column name="CustomerId"/>
    </many-to-one> 
</class>

<class name="MGender" table="[dbo].[MGender]" optimistic-lock="none" >
    <id name="GenderCode" column="GenderCode" >
        <generator class="assigned"/>
    </id>
    <property name="Description" column="Description" /> 
    <set name="Customers" cascade="none" inverse="true" fetch="select">
        <key>
            <column name="GenderCode"/>
        </key>
        <one-to-many class="Customer"/>
    </set> 
</class>

+3
source share
2

, unsaved-value, NHibernate , . Save .

    <id name="CustomerId" column="CustomerId" unsaved-value="???" >
        <generator class="assigned"/>
    </id>
+6

, , Id (x = > x.Id).GeneratedBy.Assigned(), , NHibernate thuis - . , , GeneratedBy.UuidString(). . , , .

0

Source: https://habr.com/ru/post/1787874/


All Articles