高分求救Hibernate中不能更新数据的问题(100)
错误内容如下:
Hibernate: update test.dbo.userinfo set username=?, password=? where id=?
Exception in thread "main "
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:91)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at gwm.com.Useroperation.update(Useroperation.java:26)
at gwm.com.Usermain.main(Usermain.java:19)
数据库是SQl2000表中有三个字段id(主键,自动增长),username,password.
插入,删除,查询,都没有问题,唯到更新这里就报错。
这是对应表的设置:
<hibernate-mapping>
<class name= "gwm.com.Userinfo " table= "userinfo " schema= "dbo " catalog= "test ">
<id name= "id " type= "integer ">
<column name= "id " />
<generator class= "increment " />
</id>
<property name= "username " type= "string ">
<column name= "username " length= "20 " />
</property>
<property name= "password " type= "string ">
<column name= "password " length= "20 " />
</property>
</class>
</hibernate-mapping>
------解决方案--------------------update test.dbo.userinfo set username=?, password=? where id=?
去掉hql中的逗号“,”。
------解决方案--------------------能否把update方法贴出来看看?
------解