首页 新闻 搜索 专区 学院

NHibernate发生如下错误,请问怎么解决

0
[已关闭问题]
<P>NHibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 1, of class: ZhuJi.Modules.CountModule.Domain.CountHour。</P> <P>public void Insert(int id, string ip, int pvs, int ips, int cookies, string area, string province, string city, int visits, DateTime addTime, string referSite, string referUrl, string os, string browser, string resolution, string respondents)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;ISession session = NHibernateHelper.GetCurrentSession();<BR>&nbsp;&nbsp;&nbsp;ITransaction tx = null;<BR>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;string hql = string.Empty;<BR>&nbsp;&nbsp;&nbsp;&nbsp;tx = session.BeginTransaction();</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;ZhuJi.Modules.CountModule.Domain.CountHour domainCountHour = new ZhuJi.Modules.CountModule.Domain.CountHour();<BR>&nbsp;&nbsp;&nbsp;&nbsp;</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;hql = string.Format("From CountHour as tmp Where tmp.Ip Like '{0}'",ip,addTime);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;IList&lt;ZhuJi.Modules.CountModule.Domain.CountHour&gt; listCountHour = session.CreateQuery(hql).List&lt;ZhuJi.Modules.CountModule.Domain.CountHour&gt;();<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (listCountHour.Count &gt; 0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Id = listCountHour[0].Id;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Ip = ip;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Ips = ips;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Pvs = listCountHour[0].Pvs + pvs;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Cookies = listCountHour[0].Cookies + cookies;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.Refresh(domainCountHour);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.Update(domainCountHour);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.Flush();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Ip = ip;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Ips = ips;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Pvs = pvs;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.Cookies = cookies;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainCountHour.AddTime = addTime;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.Save(domainCountHour);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session.Flush();<BR>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;tx.Commit();<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch (HibernateException ex)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (tx != null) tx.Rollback();<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw ex;<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;finally<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;NHibernateHelper.CloseSession();<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}</P>
逐迹工作室的主页 逐迹工作室 | 初学一级 | 园豆:200
提问于:2008-01-24 21:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册