异常如下:
严重: Servlet.service() for servlet default threw exception
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:654)
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:650)
at com.people.dao.UserDAOImpl.updateI(UserDAOImpl.java:28)
at com.people.service.UserServiceImpl.updateInterviewer(UserServiceImpl.java:38)
at com.people.action.interviewer.UpdateInterviewerAction.execute(UpdateInterviewerAction.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)问题是要实现一个修改的功能,表中有好多字段,但只修改其中的几个,每次在提交的时候都是直接在数据库中又多加了一条记录,而并非是修改
action:
public String execute() throws Exception{
User user = new User();
user.setUsername(username);
user.setPassword(password);
System.out.println(user.getUsername());
userService.updateInterviewer(user);
return SUCCESS;
}
updateInterviewer方法:
public void updateInterviewer(User user){
userDAO.updateI(user);
}
updateI方法:
public void updateI(User user) {
this.getHibernateTemplate().update(user);
}
有人说是数据库中主键的设成自增什么的,还有映射文件那我是这样写的<generator class="identity"></generator>,不知道有没有什么问题?求教啊
严重: Servlet.service() for servlet default threw exception
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:373)
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:654)
at org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:650)
at com.people.dao.UserDAOImpl.updateI(UserDAOImpl.java:28)
at com.people.service.UserServiceImpl.updateInterviewer(UserServiceImpl.java:38)
at com.people.action.interviewer.UpdateInterviewerAction.execute(UpdateInterviewerAction.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)问题是要实现一个修改的功能,表中有好多字段,但只修改其中的几个,每次在提交的时候都是直接在数据库中又多加了一条记录,而并非是修改
action:
public String execute() throws Exception{
User user = new User();
user.setUsername(username);
user.setPassword(password);
System.out.println(user.getUsername());
userService.updateInterviewer(user);
return SUCCESS;
}
updateInterviewer方法:
public void updateInterviewer(User user){
userDAO.updateI(user);
}
updateI方法:
public void updateI(User user) {
this.getHibernateTemplate().update(user);
}
有人说是数据库中主键的设成自增什么的,还有映射文件那我是这样写的<generator class="identity"></generator>,不知道有没有什么问题?求教啊
解决方案 »
- tomcat如何在web.xml中配置字符集?
- javax.mail.AuthenticationFailedException: Mailbox is currently locked
- 如何使用xml做中间数据传输来绑定数据,实现增删改等操作
- tomcat运行一段时间后自动关闭
- jsp和php哪个性能好??有前途??容易学
- 在线等:各位大侠帮帮忙啦,看看这是什么问题???非常感谢
- 动态生成出错为什么?
- 再线等候一个问题,马上结贴
- 请问关于hidden或者text类型传值问题?
- 在iframe中内嵌了一个https的页面,IE提示内容被阻止,chrome页面无法显示
- hibernate查询问题
- 大家好:开源系统“jacob_liang系统平台统一用户2.0”发布了
如果是oracle 应该是配置
<generator class="sequence">
<param name="sequence">序列名</param>
</generator>
另外 主键不应该是user的具体数据,只是一个编号
在你的代码中 user是新建的 也就是说没有id值
你用的是代理对象实现的update
代理会检测id是否存在 不存在则新增
so
你应该在修改的时候把id也同设置,这样才会去修改
你看下控制台打印的hibernate 的sql语句你就会明白了!