[英]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.