Hibernate批量更新失败

时间:2013-12-24 12:06:19

标签: mysql sql hibernate jsp batch-file

我已经这样做了几天,没有解决方案。我祈祷有人给出了足够的答案来解决这个问题。它确实是一项成就。 我想要实现的目标 界面上只有三(3)个控件 - 下拉列表,输入和提交按钮。下拉列表从数据库中的表中的列(ownerName)获取其值。要从界面执行事务,从下拉列表中选择一个值,将值输入到要提交到creditLimit列的输入框(文本框)中,并单击提交按钮。要更新的数据库中的表具有以下列:ownerName,crediLimit和id等。不会插入新记录,而只是通过从下拉列表中为所选ownerName指定值作为creditLimit来更新现有记录。 这是JSP代码:

<tr>
                    <td><form:label path="ownerName">Select Overdraft User:</form:label></td>
                    <td><form:select path="ownerName" name = "ownerName" items = "${addMembersListToDropdown}"></form:select></td>
                </tr>
                <tr>
                    <td><form:label path="cyclosUsersCreditLimit" name = "cyclosUsersCreditLimit">Enter an Amount:</form:label></td>
                    <td><form:input path="cyclosUsersCreditLimit" name = "cyclosUsersCreditLimit"/></td>
                </tr>
                <tr><td></td><td><input type = "submit" value = "Grant Overdraft"></td></tr>

这是DAO代码: 此代码将数据库中表的ownerName列添加到下拉控件 - 它的工作

@SuppressWarnings("unchecked")
    @Override
    public List<CyclosUsers> addToDropDown() {
        return sessionFactory.getCurrentSession().createSQLQuery("SELECT owner_name FROM accounts").list();
    }

此代码用于更新数据库中表中的ownerName记录 - 无效。

@Override
    public void updateCyclosUsers(CyclosUsers cyclosUsers) {
        sessionFactory.getCurrentSession().update(cyclosUsers);
    }

这是Controller代码 这段代码似乎不起作用。它假设执行更新声明。

@RequestMapping("/updateCyclosUsers")
    public ModelAndView updateCyclosUsers(@ModelAttribute CyclosUsers cyclosUsers, BindingResult result, HttpServletRequest request)
    {
        cyclosUsersService.updateCyclosUsers(cyclosUsers);
        System.out.println("Save User Data");
        return new ModelAndView("redirect:cyclosUsersList.html");
    }

当我运行页面时,一切正常,只有当我尝试执行错误显示的事务时才会出现问题。表示表中没有更新记录,此错误:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.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: 1
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

org.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: 1
    org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:675)
    org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
    org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:412)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    com.sun.proxy.$Proxy16.updateCyclosUsers(Unknown Source)
    nigeria.development.foundation.controller.CyclosUsersController.updateCyclosUsers(CyclosUsersController.java:53)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
    org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
    org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
    org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
    org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
    org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
    org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
    org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:412)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    com.sun.proxy.$Proxy16.updateCyclosUsers(Unknown Source)
    nigeria.development.foundation.controller.CyclosUsersController.updateCyclosUsers(CyclosUsersController.java:53)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:601)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:563)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

0 个答案:

没有答案