Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31424825/article/details/85302566
作者:LoveEmperor-王子様  

Could not synchronize database state with session org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

  • 原因1:数据Id重复
  • 原因2:可能修改方法错用为新增

Struts+Spring+Hibernate出错Batch update returned unexpected row count from update:0 actual row count: 7810893

02-26

使用Struts+Spring+Hibernate开发,出错提示org.hibernate.HibernateException: Batch update returned unexpected row count from update: 0 actual row count: 7810893 expected: 1rn各位高手,教教我rnstruts-config.xml配置 rn rn rn rn rn控制器 rnpackage action; rnimport javax.servlet.http.HttpServletRequest; rnimport javax.servlet.http.HttpServletResponse; rnimport org.apache.struts.action.Action; rnimport org.apache.struts.action.ActionForm; rnimport org.apache.struts.action.ActionForward; rnimport org.apache.struts.action.ActionMapping; rnimport org.apache.struts.action.ActionMessage; rnimport org.apache.struts.action.ActionMessages; rnrnimport dao.ActorDao; rnimport orm.Actor; rnimport bean.LogActor; rnrnpublic class LogAction extends Action rnrnprivate ActorDao logindao; rnrnpublic ActionForward execute(ActionMapping map, ActionForm form, rnHttpServletRequest request, HttpServletResponse response) throws Exception rnActionMessages errors = new ActionMessages(); rnString name = (String)((LogActor)form).getName(); rnString sex = (String)((LogActor)form).getSex(); rnString income = (String)((LogActor)form).getIncome(); rnString pbackground = (String)((LogActor)form).getPbackground(); rnString wexperience = (String)((LogActor)form).getWexperience(); rnemail = new String(email.getBytes("ISO-8859-1"),"GB2312"); rnActor actor = new Actor(); rn actor.setName(name); rn actor.setSex(sex); rn actor.setIncome(income); rn actor.setPbackground(pbackground); rn actor.setWexperience(wexperience); rnif(logindao.RegActor(actor)) rnreturn (map.findForward("success")); rnelse rnerrors.add("fail_4",new ActionMessage("Register.error.d")); rnsaveErrors(request,errors); rnreturn (map.getInputForward()); rn rn rnpublic ActorDao getLogindao() rnreturn logindao; rn rnpublic void setLogindao(ActorDao logindao) rnthis.logindao = logindao; rn rn rnHibernate和Spring共用一个配置文件,上边控制器的配置内容为 rn rn rn rn rn rn rnrn rn rn rn rn

session.save(p) ; 的时候提示Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1

06-01

查询的时候正常就是save的时候提示错误数据库mysql 以下是错误提示和源代码 高手帮看看啊 rn错误提示 rnException in thread "main" org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1 rnat org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92) rnat org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78) rnat org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57) rnat org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174) rnat org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226) rnat org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136) rnat org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274) rnat org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) rnat org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730) rnat org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324) rnat org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86) rnat com.free.dome01.PersonOperate.insert(PersonOperate.java:41) rnat com.free.dome01.TestPO.main(TestPO.java:21) rnrn数据库 rnCREATE TABLE person rn( rnid varchar(32) not null primary key , rnname varchar(20) not null , rnpassword varchar(20) not null , rnsex varchar(2) , rnemail varchar(30) rn) ; rnrnPerson.hbm.xml rnrn rn rnrn rn rn rn rnrn rn rn rn rnrn rn rn rn rn rn rn rnrnrnPersonOperate.java rnrnrnpackage com.free.dome01; rnrnimport java.util.Iterator; rnimport java.util.List; rnrnimport org.hibernate.Query; rnimport org.hibernate.Session; rnimport org.hibernate.SessionFactory; rnimport org.hibernate.Transaction; rnimport org.hibernate.cfg.Configuration; rnrn/* rn* 具体操作Hibernate的类: rn* 增加、删除、修改、按ID查询、模糊查询、查询全部操作 rn* */ rnpublic class PersonOperate rn// 在Hibernate中,所有的操作都是通过Session完成 rn// 此Session不同于JSP的Session rnprivate Session session = null ; rnrn// 在构造方法之中实例化session对象 rnpublic PersonOperate() rn rn// 找到Hibernate配置 rnConfiguration config = new Configuration().configure() ; rn// 从配置中取出SessionFactory rnSessionFactory factory = config.buildSessionFactory() ; rn// 从SessionFactory中取出一个Session rnthis.session = factory.openSession() ; rn rnrn// 所有的操作都是通过session进行的 rn// 向数据库中增加数据 rnpublic void insert(Person p) rn rn// 开始事务 rnTransaction tran = this.session.beginTransaction() ; rn// 执行语句 rnthis.session.save(p) ; rn// 提交事务 rntran.commit() ; rn// 关闭Session rnthis.session.close() ; rn rnrn// 修改 rnpublic void update(Person p) rn rn// 开始事务 rnTransaction tran = this.session.beginTransaction() ; rn// 执行语句 rnthis.session.update(p) ; rn// 提交事务 rntran.commit() ; rn rnrn// 按ID查询:推荐使用HQL —— 是Hibernate官方推荐的查询语言 rnpublic Person queryById(String id) rn rnPerson p = null ; rn// 使用Hibernate查询语言 rnString hql = "FROM Person as p WHERE p.id=?" ; rn// 通过Query接口查询 rnQuery q = this.session.createQuery(hql) ; rnq.setString(0,id) ; rnList l = q.list() ; rnIterator iter = l.iterator() ; rnif(iter.hasNext()) rn rnp = (Person)iter.next() ; rn rnreturn p ; rn rnrn// 删除数据 rn// Hibernate2、Hibernate 3通用的删除 rn// 使用此方法删除数据之前,必须先查找到数据对象,性能呢? rnpublic void delete(Person p) rn rnTransaction tran = this.session.beginTransaction() ; rn// 执行语句 rnthis.session.delete(p) ; rn// 提交事务 rntran.commit() ; rn rnrn// 在Hibernate 3之中根据HQL中的语句进行了修改,增加了删除指令 rnpublic void delete(String id) rn rnString hql = "DELETE Person WHERE id=?" ; rnQuery q = this.session.createQuery(hql) ; rn// 把参数设置 rnq.setString(0,id) ; rn// 执行更新语句 rnq.executeUpdate() ; rn// 进行事务处理 rnthis.session.beginTransaction().commit() ; rn rnrn// 查询全部数据,写HQL rnpublic List queryAll() rn rnList l = null ; rnString hql = "FROM Person as p" ; rnQuery q = this.session.createQuery(hql) ; rnl = q.list() ; rnreturn l ; rn rnrn// 模糊查询 rnpublic List queryByLike(String cond) rn rnList l = null ; rnString hql = "FROM Person as p WHERE p.name like ?" ; rnQuery q = this.session.createQuery(hql) ; rnq.setString(0,"%"+cond+"%") ; rnl = q.list() ; rnreturn l ; rn rn rnrnPerson.java rnrnpackage com.free.dome01; rn// POJO类 rnpublic class Person rn// 写入若干属性 rnprivate String id ; rnprivate String name ; rnprivate String password ; rnprivate String sex ; rnprivate String email ; rnpublic String getEmail() rnreturn email; rn rnpublic void setEmail(String email) rnthis.email = email; rn rnpublic String getId() rnreturn id; rn rnpublic void setId(String id) rnthis.id = id; rn rnpublic String getName() rnreturn name; rn rnpublic void setName(String name) rnthis.name = name; rn rnpublic String getPassword() rnreturn password; rn rnpublic void setPassword(String password) rnthis.password = password; rn rnpublic String getSex() rnreturn sex; rn rnpublic void setSex(String sex) rnthis.sex = sex; rn rn rnrnrnTestPO.java rnrnrnpackage com.free.dome01; rnrnimport java.util.Iterator; rnimport java.util.List; rnrnpublic class TestPO rnrn/** rn* @param args rn*/ rnpublic static void main(String[] args) rn// TODO 自动生成方法存根 rn// 生成POJO类实例化对象 rnPerson p = new Person() ; rnp.setId("LXH") ; rnp.setName("李兴华") ; rnp.setPassword("www.mldn.cn") ; rnp.setSex("男") ; rnp.setEmail("mldnqa@163.com") ; rnPersonOperate po = new PersonOperate() ; rnpo.insert(p) ; rn// Person p = po.queryById("LXH") ; rn// System.out.println(p.getName()) ; rn// po.delete("MLDN") ; rn/* rnList l = po.queryByLike("乐") ; rnIterator iter = l.iterator() ; rnwhile(iter.hasNext()) rn rnPerson p = (Person)iter.next() ; rnSystem.out.println(p.getName()) ; rn rn*/ rn rnrn rn

Hibernate 报:Exception executing batchBatch update returned unexpected row count from update: 0 actual row count: 0 expecte

04-19

ERROR [http-8080-Processor22] (BatchingBatcher.java:60) - Exception executing batch: rnorg.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1rn at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92)rn at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:284)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:736)rn at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:330)rn at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)rn at dao.BaseDAO.mdfObj(BaseDAO.java:72)rn at action.CsdjAction.update(CsdjAction.java:51)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)rn at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1192)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:430)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at action.EncodingFilter.doFilter(EncodingFilter.java:46)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)rn at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)rn at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)rn at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)rn at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)rn at java.lang.Thread.run(Unknown Source)rn

Unexpected row count: 0; expected: 1

09-27

NHibernate对多表连接时,插入数据时报错rn説明: 現在の Web 要求を実行中に、ハンドルされていない例外が発生しました。エラーに関する詳細および例外の発生場所については、スタック トレースを参照してください。 rnrn例外の詳細: NHibernate.StaleStateException: Unexpected row count: 0; expected: 1rnrnソース エラー: rnrnrn行 112: catch (Exception ex)rn行 113: rn行 114: throw ex;rn行 115: rn行 116: rn rnrnソース ファイル: c:\Documents and Settings\zhangxiuyan\My Documents\Visual Studio 2005\WebSites\Web\UserManager.aspx.cs 行: 114 rnrnスタック トレース: rnrnrn[StaleStateException: Unexpected row count: 0; expected: 1]rn NHibernateWebDemo.Web.UserManager.wbtn_Save_Click(Object sender, EventArgs e) in c:\Documents and Settings\zhangxiuyan\My Documents\Visual Studio 2005\WebSites\Web\UserManager.aspx.cs:114rn System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96rn System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +116rn System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31rn System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32rn System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839rnrn表结构为Groupu GroupID PKrn GroupNamern Users LogonID PKrn Name varchar(40),rn Password varchar(20),rn EmailAddress varchar(40) ,rn LastLogon datetimern GroupID FKrnrnuser.hbm.xml文件如下rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn rnrnUSER.CS文件如下rnusing System;rnusing System.Collections;rnrnnamespace NHibernateWebDemo.Modelrnrn #region Userrnrn /// rn /// User object for NHibernate mapped table 'Users'.rn /// rn public class Userrn rn #region Member Variablesrn rn protected string _id;rn protected string _name;rn protected string _password;rn protected string _emailAddress;rn protected DateTime _lastLogon;rn protected Groupu _groupu;rnrn #endregionrnrn #region Constructorsrnrn public User() rnrn public User( string name, string password, string emailAddress, DateTime lastLogon, Groupu groupu )rn rn this._name = name;rn this._password = password;rn this._emailAddress = emailAddress;rn this._lastLogon = lastLogon;rn this._groupu = groupu;rn rnrn #endregionrnrn #region Public Propertiesrnrn public virtual string Idrn rn get return _id;rn setrn rn if ( value != null && value.Length > 20)rn throw new ArgumentOutOfRangeException("Invalid value for Id", value, value.ToString());rn _id = value;rn rn rnrn public virtual string UserNamern rn get return _name; rn setrn rn if ( value != null && value.Length > 40)rn throw new ArgumentOutOfRangeException("Invalid value for Name", value, value.ToString());rn _name = value;rn rn rnrn public virtual string Passwordrn rn get return _password; rn setrn rn if ( value != null && value.Length > 20)rn throw new ArgumentOutOfRangeException("Invalid value for Password", value, value.ToString());rn _password = value;rn rn rnrn public virtual string EmailAddressrn rn get return _emailAddress; rn setrn rn if ( value != null && value.Length > 40)rn throw new ArgumentOutOfRangeException("Invalid value for EmailAddress", value, value.ToString());rn _emailAddress = value;rn rn rnrn public virtual DateTime LastLogonrn rn get return _lastLogon; rn set _lastLogon = value; rn rnrn public virtual Groupu Groupurn rn get return _groupu; rn set _groupu = value; rn rnrn rnrn #endregionrn rn #endregionrnrnGroupu.hbm.xml文件如下rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnGroupu.cs文件如下rnusing System;rnusing System.Collections;rnrnnamespace NHibernateWebDemo.Modelrnrn #region Groupurnrn /// rn /// Groupu object for NHibernate mapped table 'Groupu'.rn /// rn public class Groupurn rn #region Member Variablesrn rn protected string _id;rn protected string _groupName;rn protected IList _userses;rnrn #endregionrnrn #region Constructorsrnrn public Groupu() rnrn public Groupu( string groupName )rn rn this._groupName = groupName;rn rnrn #endregionrnrn #region Public Propertiesrnrn public virtual string GroupIDrn rn get return _id;rn setrn rn if ( value != null && value.Length > 20)rn throw new ArgumentOutOfRangeException("Invalid value for Id", value, value.ToString());rn _id = value;rn rn rnrn public virtual string GroupNamern rn get return _groupName; rn setrn rn if ( value != null && value.Length > 20)rn throw new ArgumentOutOfRangeException("Invalid value for GroupName", value, value.ToString());rn _groupName = value;rn rn rnrn public virtual IList Usersesrn rn getrn rn if (_userses==null)rn rn _userses = new ArrayList();rn rn return _userses;rn rn set _userses = value; rn rnrn rnrn #endregionrn rn #endregionrnrn汗一个,,初学NHibernate,自己对比了很久,可能配置文件有问题,可不知道哪出问题了.网上似乎也没有见到有1对多表联的例子,研究过这东东的高手来看一下,不胜感激.

org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1

01-01

2009-1-1 13:13:41 org.apache.tomcat.util.http.Parameters processParametersrn警告: Parameters: Invalid chunk ignored.rn这个是要更新的数据。也是实体。数据我都获得了。rnyern123456rn正常rn2rnHibernate: update crm.dbo.sys_user set user_name=?, user_password=?, user_Fettle=?, role_id=? where user_id=?rn2009-1-1 13:13:46 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet action threw exceptionrnorg.hibernate.StaleStateException: Unexpected row count: 0 expected: 1rn at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:27)rn at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2204)rn at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)rn at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)rn at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)rn at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)rn at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)rn at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)rn at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:654)rn at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:650)rn at org.group3.chen.daoImpl.SysUserDAOImpl.update(SysUserDAOImpl.java:38)rn at org.group3.chen.bizImpl.SysUseBizImpl.update(SysUseBizImpl.java:53)rn at com.yourcompany.struts.chen.action.SysuserAction.doUpdateUser(SysuserAction.java:187)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)rn at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)rn at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619)rnrn我使用spring 框架的HibernateDaoSupport 这个类的更新方法rn问什么使用更新方法会报这个错误,,高手看看!!谢谢rn可是更新方法我测试过了。可以更新数据,可是到action这里调用就不可以了报以上错误。。急 啊

hibernate save (Batch update returned unexpected row count from update [0];)

08-30

这个是保存代码[code=Java] public boolean save(UomConversion transientInstance) rn boolean status=false;rn log.debug("saving UomConversion instance");rn try rn Session session=getSession();rn Transaction tc=session.beginTransaction();rn session.save(transientInstance);rn tc.commit();rn status=true;rn log.debug("save successful");rn catch (RuntimeException re) rn log.error("save failed", re);rn throw re;rn rn return status;rn [/code]rn这个是配置[code=XML]rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn[/code]rnrn报错信息:rnHibernate: insert into SCISTEST.dbo.UOM_CONVERSION (Conversion_Rate, User_Add, Date_Add, User_Update, Date_Update, Client_Code, Product_No, UOM_From, UOM_To) values (?, ?, ?, ?, ?, ?, ?, ?, ?)rn2011-8-30 12:49:49 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet action threw exceptionrnorg.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1rn at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)rn at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)rn at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)rn at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)rn at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)rn at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)rn at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)rn at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)rn at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)rn at com.dao.UomConversionDAO.save(UomConversionDAO.java:53)rn at com.biz.UomConversionBIZ.save(UomConversionBIZ.java:11)rn at com.struts.action.ProductMAction.insertProductM(ProductMAction.java:73)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)rn at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Unknown Source)rn

hibernate的主键自增长异常!!Batch update returned unexpected row count from update [0]; a

11-25

在向mysql数据库中插入数据时,在出现异常如下70927 [http-8080-1] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with sessionrnorg.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1rn at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)rn at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)rn at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)rn at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)rn at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)rn at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)rn at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1179)rn at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58)rn at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)rn at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:145)rn at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:95)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:927)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:737)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)rn at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)rn at com.yhy.HappyStudy.serve.UserServe$$EnhancerByCGLIB$$d295bb47.createUser()rn at com.yhy.HappyStudy.action.UserAction.create(UserAction.java:15)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)rn at java.lang.Thread.run(Thread.java:619)rn下面是主键的hibernate配置:rn[code=Java][/code]rn rn rn rn看了网上好多说法,这里申明,没有在程序中给ID赋值,完全是自动赋值;rn不能解决,求助各位。谢谢!

hibernate 使用update是抛出异常:Batch update returned unexpected row count from update:

11-22

我就是想从数据库(mysql)中查出对象后,更改它的一些属性,用update方法更新这个对象,就抛出下面一大堆异常!这是怎么回事啊?rn异常如下:rn21:24:25,718 ERROR AbstractBatcher:61 - Exception executing batch: rnorg.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1rn at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)rn at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)rn at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)rn at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)rn at util.HibernateUtil.commit(HibernateUtil.java:25)rn at dao.UserDao.update(UserDao.java:131)rn at face.LoginFrame$ButtonAction.actionPerformed(LoginFrame.java:639)rn at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)rn at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)rn at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)rn at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)rn at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)rn at java.awt.Component.processMouseEvent(Component.java:6216)rn at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)rn at java.awt.Component.processEvent(Component.java:5981)rn at java.awt.Container.processEvent(Container.java:2041)rn at java.awt.Component.dispatchEventImpl(Component.java:4583)rn at java.awt.Container.dispatchEventImpl(Container.java:2099)rn at java.awt.Component.dispatchEvent(Component.java:4413)rn at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)rn at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)rn at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)rn at java.awt.Container.dispatchEventImpl(Container.java:2085)rn at java.awt.Window.dispatchEventImpl(Window.java:2475)rn at java.awt.Component.dispatchEvent(Component.java:4413)rn at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)rn at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)rn at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)rn at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)rn at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)rn21:24:25,734 ERROR AbstractFlushingEventListener:299 - Could not synchronize database state with sessionrnorg.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1rn at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:93)rn at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:79)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)rn at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)rn at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)rn at util.HibernateUtil.commit(HibernateUtil.java:25)rn at dao.UserDao.update(UserDao.java:131)rn at face.LoginFrame$ButtonAction.actionPerformed(LoginFrame.java:639)rn at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)rn at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)rn at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)rn at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)rn at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)rn at java.awt.Component.processMouseEvent(Component.java:6216)rn at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)rn at java.awt.Component.processEvent(Component.java:5981)rn at java.awt.Container.processEvent(Container.java:2041)rn at java.awt.Component.dispatchEventImpl(Component.java:4583)rn at java.awt.Container.dispatchEventImpl(Container.java:2099)rn at java.awt.Component.dispatchEvent(Component.java:4413)rn at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)rn at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)rn at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)rn at java.awt.Container.dispatchEventImpl(Container.java:2085)rn at java.awt.Window.dispatchEventImpl(Window.java:2475)rn at java.awt.Component.dispatchEvent(Component.java:4413)rn at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)rn at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)rn at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)rn at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)rn at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)rn at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)rnrn//下面是我自己写的一些函数:rn//UserDao中的update方法:rnrnpublic void update(User user) rn HibernateUtil.getSession().update(user);rn HibernateUtil.commit();rn rnrnrnrn//HibernateUtil类:rnpackage util;rnrnimport org.hibernate.HibernateException;rnimport org.hibernate.Session;rnimport org.hibernate.SessionFactory;rnimport org.hibernate.Transaction;rnimport org.hibernate.cfg.Configuration;rnrnpublic class HibernateUtil rn private static SessionFactory sf;rn private static Transaction ts;rn private static Session session;rn static rn sf = new Configuration().configure().buildSessionFactory();rn rnrn public static Session getSession() rn session = sf.getCurrentSession();rn ts = session.beginTransaction();rn return session;rn rnrn public static void commit() rn try rn ts.commit();rn catch (HibernateException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rnrn

HibernateOptimisticLockingFailureException: Batch update returned unexpected row

05-25

rn数据库为mysql,实体配置文件:rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn在执行 getHibernateTemplate().fine(),rnrn(TcTaskMap)this.find("from TcTaskMap t where t.nodeType='node' and t.nodeId=" + node.getNodeId()).get(0);rn时报错如下:rnorg.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1rn at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:657)rn at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)rn at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)rn at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)rn at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:917)rn at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:909)rn at com.gsta.common.dao.BaseDaoImpl.find(BaseDaoImpl.java:260)rn at com.gsta.common.dao.BaseDaoImpl.findOne(BaseDaoImpl.java:2295)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)rn at com.sun.proxy.$Proxy6.findOne(Unknown Source)rn[color=#FF0000] at com.gsta.task.service.TaskMgrServiceImpl.findTcTaskMap(TaskMgrServiceImpl.java:2214)rn at com.gsta.task.service.TaskMgrServiceImpl.saveUIMap4Node(TaskMgrServiceImpl.java:4223)rn at com.gsta.task.service.TaskMgrServiceImpl.saveUIMap(TaskMgrServiceImpl.java:4194)[/color]rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)rn at com.sun.proxy.$Proxy16.saveUIMap(Unknown Source)rn at com.gsta.task.action.UIMapAction.save(UIMapAction.java:234)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)rn at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1rn at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)rn at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)rn at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)rn at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)rn at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)rn at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)rn at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)rn at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:926)rn at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)

Hibernate update(obj)异常 Unexpected row count: 137 expected: 1

08-05

[code=Java]org.hibernate.HibernateException: Unexpected row count: 137 expected: 1rn at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:33)rn at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2268)rn at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2180)rn at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2450)rn at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:91)rn at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:993)rn at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:340)rn at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)rn at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:490)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:495)rn at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:468)rn at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:258)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)rn at $Proxy48.saveOrUpdate(Unknown Source)rn at com.turbo.cinema.film.UpdateTheaterInfoAction.execute(UpdateTheaterInfoAction.java:343)rn at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at com.turbo.cinema.common.CharsetEncodFilter.doFilter(CharsetEncodFilter.java:85)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)rn at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)rn at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)rn at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)rn at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)rn at java.lang.Thread.run(Thread.java:619)rn[/code]rnrn这个异常是用 hibernate update(obj) 方法报错的, 请问,这个异常是为什么报的!!

hibernate 删除时碰到了这个问题。。。费解 Batch update returned unexpected row count from update

01-29

org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 3; expected: 1rn at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:95)rn at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)rn at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)rn at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)rn at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)rn at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)rn at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2497)rn at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2715)rn at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:97)rn at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)rn at com.meyoung.dao.man.patrol.impl.PatrolPlanDaoImpl.delete(PatrolPlanDaoImpl.java:49)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)rn at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)rn at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)rn at $Proxy46.delete(Unknown Source)rn at com.meyoung.manager.man.patrol.impl.PatrolPlanManagerImpl.deleteById(PatrolPlanManagerImpl.java:365)rn at com.meyoung.controller.ServicesController.delete(ServicesController.java:269)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)rn at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)rn at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)rn at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at com.brlue.servlet.filter.ProcessTimeFilter.doFilter(ProcessTimeFilter.java:22)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)rn at java.lang.Thread.run(Thread.java:619)rn具体情况是这样的,在测试服务器上进行删除操作时会报错,不管是新增的数据,还是已经有的数据在执行删除时都会爆上面的错误。于是我在本地上测试了下,发现删除没有问题,但是测试服务器上确实会报错。我便把测试数据库拷贝到本地上,然后本地执行删除操作。。就爆了上面的错误。。。但是我本地上从新新增的数据进行删除操作他却不会报错。。。rn 首先:本地上的代码和测试上的代码是同步的,这点是可以肯定的rn 出现这个原因:我猜想 1.很大一部分原因是测试数据的问题。但是我不敢排除代码是否有问题,因为测试上新增删除也是会爆错。请问下,大神这个原因是什么造成的?rn 对了,对这个新增操作的时候,会跟别的表进行关联,有两个表是一个一对多的关系,这是hbm.xml的配置[img=http://img.bbs.csdn.net/upload/201601/29/1454067994_804683.png][/img]在进行新增操作的时候,我会对这个many的两张表进行先删除在插入,当时做的时候因为进行了one-to-many,只能对一张表进行删除插入,当对第二张进行操作的时候就会爆错了,没办法,只能在当第一张表进行完后,在对那个set进行clear()了一下,这样就可以把数据保存进行了[img=http://img.bbs.csdn.net/upload/201601/29/1454068280_349241.png][/img][img=http://img.bbs.csdn.net/upload/201601/29/1454068058_298743.png][/img]。。我在想是不是在进行新增的时候,这样操作了,对删除有影响?所以问问各位大神。。造成这样的错误的原因。。。。可能我表述的不是很清楚。。但是进行上面操作会有这样的问题。。能否有碰到过的,指点下。。。。

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试