开发者

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)

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&开发者_运维知识库gt;
    <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

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? Use ShowSql() when configuring Fluent and it will output to the console what SQL it is attempting to execute. The actual error messages appears to be a SQL error message.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜