问题描述
(无满意结帐也会扣分...天纳)异常:Unexpectedrowcount:0;expected:1映射文件如下:<?xmlversion="1.0"encoding="utf-8"?><hibernate-mappingxmlns="urn:nhibernate-mapping-2.2"><classname="IQTC.Model.POCO.SW.AlterationDayPlan,IQTC.Model"table="SW_AlterationDayPlan"><idname="DayPlanId"type="String"unsaved-value="0"><columnname="DayPlanId"length="50"sql-type="varchar"not-null="false"unique="true"/><generatorclass="assigned"/></id><propertyname="MonthPlanId"type="String"><columnname="MonthPlanId"length="50"sql-type="varchar"not-null="true"/></property><propertyname="ConstructDate"type="String"><columnname="ConstructDate"length="50"sql-type="varchar"not-null="true"/></property><propertyname="LeadId"type="String"><columnname="LeadId"length="50"sql-type="varchar"not-null="true"/></property><propertyname="ConstructSpace"type="String"><columnname="ConstructSpace"length="50"sql-type="varchar"not-null="true"/></property><propertyname="ConstructTermId"type="String"><columnname="ConstructTermId"length="50"sql-type="varchar"not-null="true"/></property><propertyname="Remark"type="String"><columnname="Remark"length="100"sql-type="varchar"not-null="true"/></property><propertyname="StationName"type="String"><columnname="StationName"length="50"sql-type="varchar"not-null="true"/></property><propertyname="LeadWorkarea"type="String"><columnname="LeadWorkarea"length="50"sql-type="varchar"not-null="true"/></property><propertyname="LineId"type="String"><columnname="LineId"length="50"sql-type="varchar"not-null="true"/></property><propertyname="StationId"type="String"><columnname="StationId"length="50"sql-type="varchar"not-null="true"/></property><propertyname="LineType"type="String"><columnname="LineType"length="50"sql-type="varchar"not-null="true"/></property><propertyname="MoEstate"type="String"><columnname="MoEstate"length="100"sql-type="varchar"not-null="true"/></property><propertyname="RegId"type="String"><columnname="RegId"length="50"sql-type="varchar"not-null="true"/></property><propertyname="DateTimeNow"type="String"><columnname="DateTimeNow"length="50"sql-type="Datetime"not-null="true"/></property></class></hibernate-mapping>调用SaveOrUpdate()publicvoidUpdate(AlterationDayPlanitem){ISessionsession=newSW.Generic.NhibernateSession().GetSession();ITransactiontransaction=session.BeginTransaction();try{if(item!=null){session.SaveOrUpdate(item);transaction.Commit();session.Flush();}}catch(HibernateExceptionhex){transaction.Rollback();throwhex;}finally{session.Close();}}
解决方案
解决方案二:
楼主你的item不是当前Session取得的,那么至少应该是"游离"状态的才可以(新的ISession可以还原游离的item为持久对象),你这种方式插入新的记录应该是可以的(其他地方代码没错的话),但更新可能会有问题。可能是这个原因吧:建议这样修改:publicvoidUpdate(AlterationDayPlanitem,ISessionsession){ITransactiontransaction=session.BeginTransaction();try{if(item!=null){session.SaveOrUpdate(item);transaction.Commit();session.Flush();}}catch(HibernateExceptionhex){transaction.Rollback();throwhex;}finally{session.Close();}}
item是ISession取得的,所以和ISession一起传入
解决方案三:
谢谢你的建议,我试一下