小编TMS*_*TMS的帖子

NHibernate警告和数据未保存

当我通过调用SaveOrUpdate()进行保存时,我收到此警告,并且在调用Transaction.Commit()之后数据未保存在数据库中.

NHibernate.Engine.ForeignKeys - 无法确定具有指定标识符[primarykey]的[项目名称]是暂时的还是分离的; 查询数据库.在会话中使用显式Save()或Update()来防止这种情况.

我正在插入一个新对象.谷歌搜索告诉我调用Save()而不是SaveOrUpdate():意味着Save()仅用于插入.

我在谷歌搜索,并没有看到太多关于这一点.任何人都可以给我这个问题或这个警告的建议吗?

编辑:这是模拟的样本映射文件 -

<?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>
Run Code Online (Sandbox Code Playgroud)

<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"/> …
Run Code Online (Sandbox Code Playgroud)

nhibernate

3
推荐指数
1
解决办法
2839
查看次数

标签 统计

nhibernate ×1