简体   繁体   English

流利的NHibernate在插入/保存时导致“将数字转换为数据类型数字的算术溢出错误”

[英]Fluent NHibernate cause an “Arithmetic overflow error converting numeric to data type numeric” on insert/save

This code produces an " Arithmetic overflow error converting numeric to data type numeric " 此代码产生“ 将数字转换为数据类型数字的算术溢出错误

Session.Save(new Keyword
{
    Approved = true,
    Custom = false,
    Value = "toto",
    Language = "en"
});

The mapping of Keyword is the following 关键字的对应关系如下

public class KeywordMap : ClassMap<Keyword>
{
    public KeywordMap()
    {
        Table("PRODUCTS_Keywords");

        Id(x => x.Id, "keywordID").GeneratedBy.Identity();

        Map(x => x.Value, "keyword")
            .Not.Nullable();

        Map(x => x.Language, "language")
            .Not.Nullable();

        Map(x => x.Approved, "approved")
            .Not.Nullable();

        Map(x => x.Custom, "custom")
            .Not.Nullable();
    }
}

The entity of Keyword is the following 关键字的实体如下

public class Keyword
{
    public virtual Int64 Id { get; private set; }
    public virtual string Value { get; set; }
    public virtual string Language { get; set; }
    public virtual bool Approved { get; set; }
    public virtual bool Custom { get; set; }
}

This is the representation of table PRODUCTS_Keyword in my database (I use MSSQL 2008 R2) 这是数据库中表PRODUCTS_Keyword的表示形式(我使用MSSQL 2008 R2)

CREATE TABLE [dbo].[PRODUCTS_Keywords](
    [keywordID] [bigint] IDENTITY(1,1) NOT NULL,
    [keyword] [nvarchar](50) NOT NULL,
    [language] [char](2) NOT NULL,
    [approved] [bit] NOT NULL,
    [custom] [bit] NOT NULL,
PRIMARY KEY CLUSTERED

This is the exported mapping for Keyword 这是关键字的导出映射

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2" name="Keyword, Main, Version=1.4.0.0, Culture=neutral, PublicKeyToken=null" table="PRODUCTS_Keywords">
    <id name="Id" type="System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="keywordID" />
      <generator class="identity" />
    </id>
    <property name="Value" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="keyword" not-null="true" />
    </property>
    <property name="Language" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="language" not-null="true" />
    </property>
    <property name="Approved" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="approved" not-null="true" />
    </property>
    <property name="Custom" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="custom" not-null="true" />
    </property>
  </class>
</hibernate-mapping>

This is the stacktrace 这是堆栈跟踪

at NHibernate.AdoNet.SqlClientSqlCommandSet.ExecuteNonQuery()
at NHibernate.AdoNet.SqlClientBatchingBatcher.DoExecuteBatch(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatchWithTiming(IDbCommand ps)
at NHibernate.AdoNet.AbstractBatcher.ExecuteBatch()
at NHibernate.AdoNet.AbstractBatcher.OnPreparedCommand()
at NHibernate.AdoNet.AbstractBatcher.PrepareCommand(CommandType type, SqlString sql, SqlType[] parameterTypes)
at NHibernate.AdoNet.AbstractBatcher.PrepareBatchCommand(CommandType type, SqlString sql, SqlType[] parameterTypes)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Action.EntityInsertAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteInserts()
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
at NHibernate.Impl.SessionImpl.Save(Object obj)

Currently, there are 266 016 records in table PRODUCTS_Keywords and the Max(keywordID) is 8 942 223 当前,表PRODUCTS_Keywords中有266,016条记录,最大(keywordID)为8942223

What is the cause of the problem and how can I fix it ? 问题的原因是什么,如何解决?

Thank you 谢谢

The only thing that seems questionable about your setup is having the set accessor be private. 关于您的设置似乎唯一有问题的是将设置访问器设为私有。 That might be fine, but I've only ever seen public and protected used in these situations. 可能很好,但是我只在这些情况下看到过公开和受保护的使用情况。

Can you show the sql statement that's being generated by fluent? 您可以显示由fluent生成的sql语句吗? Use ShowSql() when configuring Fluent and it will output to the console what SQL it is attempting to execute. 在配置Fluent时使用ShowSql(),它将向控制台输出它试图执行的SQL。 The actual error messages appears to be a SQL error message. 实际的错误消息似乎是SQL错误消息。

暂无
暂无

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

相关问题 c# 中的 ExecuteNonQuery() 抛出异常 - 将数字转换为数据类型数字的算术溢出错误 - ExecuteNonQuery() from c# throwing exception - arithmetic overflow error converting numeric to data type numeric 将varchar转换为数值数据类型的算术溢出错误。 asp.net中的错误 - Arithmetic overflow error converting varchar to data type numeric. Error in asp.net 在var.net中将varchar转换为数值类型的算术溢出错误 - Arithmetic overflow error converting varchar to data type numeric in asp.net 使用C#和SQL Server将int转换为数据类型数值的算术溢出错误 - Arithmetic overflow error converting int to data type numeric using C# and SQL Server 在SQL Server 2008中将varchar转换为数值数据类型时发生算术溢出错误 - An arithmetic overflow error occurred while converting varchar to numeric data type in SQL Server 2008 将varchar转换为数值数据类型的算术溢出错误。 尝试从数据库读取时并非每次都会发生 - Arithmetic overflow error converting varchar to data type numeric. when trying to read from a database DOES NOT happen every time 将数字转换为数据类型数字时出错 - Error when converting numeric to data type numeric 将数据添加到数据库时发生异常-将int转换为数字数据类型时发生溢出错误 - Exception while adding data to to the database -overflow error converting int to data type numeric 从数字数据类型转换为十进制时出错 - Error converting from numeric data type to decimal SQLException:将数据类型varchar转换为数值时出错 - SQLException: Error converting data type varchar to numeric
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM