首页 新闻 会员 周边 捐助

NHibernate报错null id in entry (don't flush the Session after an exception occurs)

0
悬赏园豆:20 [已关闭问题] 关闭于 2019-05-16 14:49
private readonly ISession _session = SessionBuilder.GetSession();

        public int Save<T>(T entity) where T 
        {
            var id = 0;
            var session = this._session;
            ITransaction tan = session.BeginTransaction();
            try
            {
                entity = session.Merge(entity);
            }
            catch
            {

            }
            try
            {
                tan.Begin();
                id = (int)session.Save(entity);
                session.Flush();
                tan.Commit();
            }
            catch (Exception e)
            {
                Log.DebugFormat("Save.Exception=>" + e.Message+ "&entity="+ JsonConvert.SerializeObject(entity));
                tan.Rollback();
                throw;
            }

            return id;
        }

偶尔会出现报错null id in entry (don't flush the Session after an exception occurs),

下面的

2019-01-22 17:02:16,088 DEBUG Ylsdai.Service.BaseService -<log4net.Error>Exception during StringFormat: 输入字符串的格式不正确。 <format>Save.Exception=>null id in Ylsdai.Domain.Entity.AgentShopSale entry (don't flush the Session after an exception occurs)&entity={"SaleId":299,"ShopId":1,"ShipId":27,"CruiseDay":0,"CruiseNight":0,"ItemId":"","AddDate":"2019-01-22T17:02:15.9195763+08:00","DepartureCity":"厦门","DisembarkCity":"厦门","IsDelete":false,"UpdateSaleType":2,"CruiseStartDate":"2000-01-01T00:00:00","CruiseEndDate":"2000-01-01T00:00:00"}</format><args>{}</args></log4net.Error>
2019-01-22 17:02:19,009 DEBUG Ylsdai.Service.BaseService -<log4net.Error>Exception during StringFormat: 输入字符串的格式不正确。 <format>Save.Exception=>null id in Ylsdai.Domain.Entity.AgentShopSale entry (don't flush the Session after an exception occurs)&entity={"SaleId":300,"ShopId":1,"ShipId":27,"CruiseDay":0,"CruiseNight":0,"ItemId":"","AddDate":"2019-01-22T17:02:19.0050508+08:00","DepartureCity":"厦门","DisembarkCity":"厦门","IsDelete":false,"UpdateSaleType":2,"CruiseStartDate":"2000-01-01T00:00:00","CruiseEndDate":"2000-01-01T00:00:00"}</format><args>{}</args></log4net.Error>
2019-01-22 17:03:10,991 DEBUG Ylsdai.Service.BaseService -<log4net.Error>Exception during StringFormat: 输入字符串的格式不正确。 <format>Save.Exception=>null id in Ylsdai.Domain.Entity.AgentShopSale entry (don't flush the Session after an exception occurs)&entity={"SaleId":301,"ShopId":1,"ShipId":27,"CruiseDay":0,"CruiseNight":0,"ItemId":"","AddDate":"2019-01-22T17:03:10.9887294+08:00","DepartureCity":"厦门","DisembarkCity":"厦门","IsDelete":false,"UpdateSaleType":2,"CruiseStartDate":"2000-01-01T00:00:00","CruiseEndDate":"2000-01-01T00:00:00"}</format><args>{}</args></log4net.Error>
2019-01-22 17:03:12,746 DEBUG Ylsdai.Service.BaseService -<log4net.Error>Exception during StringFormat: 输入字符串的格式不正确。 <format>Save.Exception=>null id in Ylsdai.Domain.Entity.AgentShopSale entry (don't flush the Session after an exception occurs)&entity={"SaleId":302,"ShopId":1,"ShipId":27,"CruiseDay":0,"CruiseNight":0,"ItemId":"","AddDate":"2019-01-22T17:03:12.7436391+08:00","DepartureCity":"厦门","DisembarkCity":"厦门","IsDelete":false,"UpdateSaleType":2,"CruiseStartDate":"2000-01-01T00:00:00","CruiseEndDate":"2000-01-01T00:00:00"}</format><args>{}</args></log4net.Error>

我把网站bin文件夹的dll文件复制出来,再复制进去提交,主键SaleId变成303,等于是主键挑掉了,并且出现了上述问题,实体映射为

[Serializable]
    public class AgentShopSale : BaseEntity
    {
        /// <summary>
        /// SaleId
        /// </summary>
        public virtual int SaleId { get; set; } 

         /// <summary>
         /// AgentId
         /// </summary>
        public virtual int ShopId { get; set; }

        /// <summary>
        /// ShipId
        /// </summary>
        public virtual int ShipId { get; set; }

        /// <summary>
        /// CruiseDay
        /// </summary>
        public virtual int CruiseDay { get; set; }

        /// <summary>
        /// CruiseNight
        /// </summary>
        public virtual int CruiseNight { get; set; }

        /// <summary>
        /// ItemId
        /// </summary>
        public virtual string ItemId { get; set; }

        /// <summary>
        /// AddDate
        /// </summary>
        public virtual DateTime AddDate { get; set; }


        /// <summary>
        /// DepartureCity
        /// </summary>
        public virtual string DepartureCity { get; set; }


        /// <summary>
        /// DisembarkCity
        /// </summary>
        public virtual string DisembarkCity { get; set; }

        /// <summary>
        /// IsDelete
        /// </summary>
        public virtual bool IsDelete { get; set; }

        /// <summary>
        /// UpdateSaleType
        /// </summary>
        public virtual int UpdateSaleType { get; set; }

        /// <summary>
        /// CruiseStartDate
        /// </summary>
        public virtual DateTime CruiseStartDate { get; set; }

        /// <summary>
        /// CruiseEndDate
        /// </summary>
        public virtual DateTime CruiseEndDate { get; set; }

    }

public class AgentShopSaleMap : ClassMapping<AgentShopSale>
{
public AgentShopSaleMap()
{
SelectBeforeUpdate(true);
DynamicUpdate(true);
//Mutable(false);
//Cache(p => p.Usage(CacheUsage.ReadWrite));
Id(p => p.SaleId, map => map.Generator(Generators.Native));
Property(p => p.ShopId);
Property(p => p.ShipId);
Property(p => p.CruiseDay);
Property(p => p.CruiseNight);
Property(p => p.ItemId);
Property(p => p.DepartureCity);
Property(p => p.DisembarkCity);
Property(p => p.AddDate);
Property(p => p.IsDelete);
Property(p => p.UpdateSaleType);
Property(p => p.CruiseStartDate);
Property(p => p.CruiseEndDate);
}
}

 

请问有大神解决了吗?不是长度的问题,长度问题应该是报“将截取字符串”,日期类型都有值的,除了主键全部可以为空,

NHibernate 版本为5.1.3

spatxos的主页 spatxos | 初学一级 | 园豆:32
提问于:2019-01-22 17:48
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册