Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1967186
  • 博文数量: 606
  • 博客积分: 9991
  • 博客等级: 中将
  • 技术积分: 5725
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-17 19:07
文章分类

全部博文(606)

文章存档

2011年(10)

2010年(67)

2009年(155)

2008年(386)

分类:

2008-08-21 19:49:49

Hibernate: update STUDENT set CLASS_ID=?, NAME=?, PASSWORD=?, FULLNAME=?, GENDER=?, ENROLLTIME=?, REMARK=? where ID=?
org.hibernate.StaleStateException: Unexpected row count: 0 expected: 1
 at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:27)
 at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2204)
 at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2118)
 at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2374)
 at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:84)
 at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:227)
 at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
 at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
 at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
 at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
 at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
 at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
 at com.wyu.exam.filter.HibernateFilter.doFilter(HibernateFilter.java:43)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
 at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
 at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
 at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
 at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
 at java.lang.Thread.run(Thread.java:619)

原理:

saveOrUpdate()方法同时包含了save()与update()方法的功能,如果传入的参数是临时对象,就调用save()方法;如果传入的参数是游离对象,就调用update()方法;如果传入的参数是持久化对象,那就直接返回。

Hibernate判断临时对象的方法

×Java对象的OID取值为null

×Java对象具有version属性并且取值为null

×在映射文件中为元素设置了unsaved-value属性,并且version属性取值与unsaved-value属性值匹配

×自定义了Hibernate的Interceptor实现类,并且Interceptor的isUnsaved()方法返回Boolean.TRUE

描述:

在项目中,执行添加事件,在..._Add.jsp文件设置了

,也就是对象的OID取值不为null,所以Hibernate把它视为游离对象,执行update()方法,所以执行了以下的HQL语句:Hibernate: update STUDENT set CLASS_ID=?, NAME=?, PASSWORD=?, FULLNAME=?, GENDER=?, ENROLLTIME=?, REMARK=? where ID=?,

解决方法:去掉

阅读(1799) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~