简体   繁体   English

NHibernate奇怪序列映射行为

[英]NHibernate Strange Sequence mapping behaviour

I am trying to figure this strange mapping behaviour of nhibernate. 我试图弄清楚nhibernate的这种奇怪的映射行为。

I Have a sequence ID in PostgreSQL and my mapping.hbm.xml file is this: 我在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>

The error that i am getting is 我得到的错误是

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

I also changed the generator type to SEQUENCE but it gives me the same error. 我也将生成器类型更改为SEQUENCE,但它给了我同样的错误。

Can anyone help? 有人可以帮忙吗?

The problem was with the nhibernate serialization. 问题出在nhibernate序列化上。

I was serializing the model to json and i was not using the code from this link JSON.NET and nHibernate Lazy Loading of Collections 我正在将模型序列化为json,但是我没有使用此链接JSON.NET和nHibernate的延迟加载代码

Actually this error is quite strange. 其实这个错误很奇怪。 My query was a 'GET' query and won't mess with the identity generation. 我的查询是“ GET”查询,不会干扰身份生成。 But even with this, nhibernate was trying to generate an incorrect identity and threw me this weird exception. 但是即使这样,nhibernate仍试图生成一个不正确的身份并将这个奇怪的异常扔给我。

Well. 好。 Problem solved.. maybe this help's someone :) 问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM