[已关闭问题]
<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> {<BR> ISession session = NHibernateHelper.GetCurrentSession();<BR> ITransaction tx = null;<BR> try<BR> {<BR> string hql = string.Empty;<BR> tx = session.BeginTransaction();</P>
<P> ZhuJi.Modules.CountModule.Domain.CountHour domainCountHour = new ZhuJi.Modules.CountModule.Domain.CountHour();<BR> </P>
<P> hql = string.Format("From CountHour as tmp Where tmp.Ip Like '{0}'",ip,addTime); <BR> IList<ZhuJi.Modules.CountModule.Domain.CountHour> listCountHour = session.CreateQuery(hql).List<ZhuJi.Modules.CountModule.Domain.CountHour>();<BR> if (listCountHour.Count > 0)<BR> {<BR> domainCountHour.Id = listCountHour[0].Id;<BR> domainCountHour.Ip = ip;<BR> domainCountHour.Ips = ips;<BR> domainCountHour.Pvs = listCountHour[0].Pvs + pvs;<BR> domainCountHour.Cookies = listCountHour[0].Cookies + cookies;<BR> session.Refresh(domainCountHour);<BR> session.Update(domainCountHour);<BR> session.Flush();<BR> }<BR> else<BR> {<BR> domainCountHour.Ip = ip;<BR> domainCountHour.Ips = ips;<BR> domainCountHour.Pvs = pvs;<BR> domainCountHour.Cookies = cookies;<BR> domainCountHour.AddTime = addTime;<BR> session.Save(domainCountHour);<BR> session.Flush();<BR> } </P>
<P> tx.Commit();<BR> }<BR> catch (HibernateException ex)<BR> {<BR> if (tx != null) tx.Rollback();<BR> throw ex;<BR> }<BR> finally<BR> {<BR> NHibernateHelper.CloseSession();<BR> }<BR> }</P>