NHibernate奇怪的序列映射行为

时间:2016-09-06 13:46:12

标签: c# asp.net-mvc postgresql nhibernate fluent-nhibernate

我试图弄清楚这种奇怪的nhibernate映射行为。

我在PostgreSQL中有一个序列ID,而我的mapping.hbm.xml文件是这样的:

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
      <class xmlns="urn:nhibernate-mapping-2.2" schema="core" name="Tecplas.Data.Models.Core.User, Tecplas.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="usuario">
        <id name="Id" type="System.Int64, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="usu_identi" />
          <generator class="native">
            <param name="sequence">seq_usuario</param>
          </generator>
        </id>
        <property name="CreatorProgram" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="usu_prog_criacao" />
        </property>
        <property name="CreationDate" type="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="usu_data_criacao" />
        </property>
        <property name="UpdateProgram" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="usu_prog_alteracao" />
        </property>
        <property name="UpdateDate" type="System.Nullable`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="usu_data_alteracao" />
        </property>
        <property name="Login" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="usu_login" />
        </property>
        <property name="Password" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <column name="usu_senha" />
        </property>
        <many-to-one class="Tecplas.Data.Models.Core.User, Tecplas.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="CreatorUser">
          <column name="usu_usu_criacao" />
        </many-to-one>
        <many-to-one class="Tecplas.Data.Models.Core.User, Tecplas.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="UpdateUser">
          <column name="usu_usu_alteracao" />
        </many-to-one>
      </class>
    </hibernate-mapping>

我得到的错误是

  "Dialect does not support identity key generation"
  .... em NHibernate.Dialect.Dialect.get_IdentitySelectString()\r\n   em GetIdentitySelectString(Object )

我也将生成器类型更改为SEQUENCE但它给了我同样的错误。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

问题在于nhibernate序列化。

我正在将模型序列化为json,而我没有使用此链接中的代码JSON.NET and nHibernate Lazy Loading of Collections

实际上这个错误很奇怪。我的查询是一个'GET'查询,不会弄乱身份生成。但即便如此,nhibernate也试图产生一个不正确的身份,并把这个奇怪的异常扔给我。

好。 问题解决了......也许这个帮助是某人:)