0
回答
项目中做一个更新操作报错:Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
开发十年,就只剩下这套Java开发体系了   

鉴于客户需要,我在建表的时候,设置的主键是assigned,也就是说主键不是自增长的,但是我在做更新的时候却报错了,下面是详细的报错信息:

2015-03-11 20:15:31 [admin1] [com.zjft.lms.web.business.OrderController]-[ERROR] 订单信息更新失败!
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
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:655)
    at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:134)
    at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:72)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:905)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:715)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy17.updateOrder(Unknown Source)
    at com.zjft.lms.web.business.OrderController.updateOrder(OrderController.java:523)
    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)
    at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
    at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
    at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.zjft.lms.common.RequestFilter.doFilter(RequestFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.zjft.lms.common.LogFilter.doFilter(LogFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.zjft.lms.utils.LoginCheckFilter.doFilter(LoginCheckFilter.java:41)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)
Caused by: 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.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:126)
    ... 51 more




下面是我的hibernate映射文件:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.zjft.lms.hibernate.Order" table="ORDER_TABLE" >
        <comment>订单信息表</comment>
        <id name="no" type="java.lang.String">
            <column name="NO" length="20" />
           <generator class="assigned"></generator>
        </id>
        <many-to-one name="hospital" class="com.zjft.lms.hibernate.HospitalInfo" fetch="join" lazy="false">
            <column name="HOSPITAL_NO" length="20" not-null="true" >
            <comment>订单所属医院</comment>
            </column>
        </many-to-one>
        
        <many-to-one name="salesman" class="com.zjft.lms.hibernate.OpTable" fetch="join" lazy="false">
            <column name="SALESMAN_NO" length="20" not-null="true" >
            <comment>销售人员编号</comment>
            </column>
        </many-to-one>
        
         <many-to-one name="operator" class="com.zjft.lms.hibernate.OpTable" fetch="join" lazy="false">
            <column name="OPERATOR_NO" length="20" not-null="true">
                <comment>操作人员编号</comment>
            </column>
        </many-to-one>
        
        <property name="requestDateTime" type="java.util.Date">
            <column name="REQUEST_DATETIME"  not-null="true">
                <comment>要求到药日期时间</comment>
            </column>
        </property>
        
         <property name="placeOrderDateTime" type="java.util.Date">
            <column name="PLACE_ORDER_DATETIME" length="7" not-null="true">
                <comment>下单时间</comment>
            </column>
        </property>
        
        <property name="calType" type="java.lang.String">
            <column name="CAL_TYPE" length="1" not-null="true">
                <comment>计算类型:0,人份;1,剂量;</comment>
            </column>
        </property>
        <property name="orderQuantity" type="java.math.BigDecimal">
            <column name="ORDER_QUANTITY" precision="22" scale="0" not-null="true">
                <comment>订单量</comment>
            </column>
        </property>
        <property name="status" type="java.lang.Integer">
            <column name="STATUS"  not-null="true">
                <comment>状态</comment>
            </column>
        </property>

        <property name="intervalTime" type="java.math.BigDecimal">
            <column name="INTERVAL_TIME" precision="22" scale="0" not-null="true">
                <comment>分钟</comment>
            </column>
        </property>
        <property name="onetimeuseamount" type="java.math.BigDecimal">
            <column name="ONETIMEUSEAMOUNT" precision="22" scale="0">
                <comment>每病人量</comment>
            </column>
        </property>
        <property name="remark" type="java.lang.String">
            <column name="REMARK" length="150">
                <comment>备注</comment>
            </column>
        </property>
         <property name="isTransPlan" type="java.lang.Integer">
            <column name="isTransPlan" precision="22" scale="0" not-null="true">
                <comment>状态</comment>
            </column>
        </property>

    </class>
</hibernate-mapping>





controller:

public ModelAndView updateOrder(HttpServletRequest request, HttpServletResponse response) {
        RetInfo retInfo = new RetInfo();
        UserSession userSession = (UserSession) request.getSession().getAttribute("userSession");
        try {
            String orderNo = request.getParameter("orderNo");
            String requestDateTimeStr = request.getParameter("requestDateTimeStr");
            String placeOrderDateTimeStr = request.getParameter("placeOrderDateTimeStr");
            String hospitalNo = request.getParameter("hospitalNo");
            String calType = request.getParameter("calType");
            BigDecimal orderQuantity = new BigDecimal(request.getParameter("orderQuantity"));
            BigDecimal intervalTime = new BigDecimal(StringUtil.parseString(request.getParameter("intervalTime")));
            BigDecimal eachDosagePerPatient = new BigDecimal(request.getParameter("eachDosagePerPatient"));
            String remark = StringUtil.parseString(request.getParameter("remark"));
            Date requestDateTime = CalendarUtil.getDateTimeFromStr(requestDateTimeStr);
            Date placeOrderDateTime = CalendarUtil.getDateTimeFromStr(placeOrderDateTimeStr);

            OrderVO ordervo = orderService.getOrderByNo(orderNo);

            ordervo.setOrderNo(orderNo);
            ordervo.setPlaceOrderDateTime(placeOrderDateTime);
            ordervo.setRequestDateTime(requestDateTime);
            ordervo.setHospitalNo(hospitalNo);
            ordervo.setCalType(calType);
            ordervo.setIntervalTime(intervalTime);
            ordervo.setOrderQuantity(orderQuantity);
            ordervo.setOnetimeuseamount(eachDosagePerPatient);
            ordervo.setNotes(remark);
            ordervo.setOperateNo(userSession.getAccount());

            this.getOrderService().updateOrder(ordervo,userSession.getAccount(),userSession.getRoleNo());
        } catch (Exception e) {
            log.error("订单信息更新失败!", e);
            retInfo.setSuccess(false);
            retInfo.setErrMsg(e.getMessage());
        }
        return new ModelAndView("json/result").addObject("retInfo", retInfo);
    }




service:

    public void updateOrder(OrderVO ordervo, String userNo, Integer roleNo) {
        
        Order order= orderDAO.getPOById(ordervo.getOrderNo());
        
        //订单处于已提交,已保存状态,则订单提交人员,总调度,订单相关的销售有权限修改
        boolean flag=false;
        if(order.getStatus()==SystemCons.ORDER_ALREADY_SUBMIT ||order.getStatus()==SystemCons.ORDER_ALREADY_SAVE){
            String operatorNo=order.getOperator().getNo();
            String salesManNo=order.getSalesman().getNo();
            if (operatorNo.equals(userNo)) {
                flag=true;
            }
            if(salesManNo.equals(userNo)){
                flag=true;
            }
            if (roleNo==SystemCons.getDispatcherRoleNo()) {
                flag=true;
            }
        }//订单处于已确认,已计划,已生产,运输中状态,只有总调度可以修改
        else if (order.getStatus()==SystemCons.ORDER_ALREADY_CONFIRM||order.getStatus()==SystemCons.ORDER_ALREADY_PLAN||order.getStatus()==SystemCons.ORDER_ALREADY_PRODUCTION||order.getStatus()==SystemCons.ORDER_ALREADY_TRANSING) {
            if (roleNo==SystemCons.getDispatcherRoleNo()) {
                flag=true;
            }
        }else //其他状态的订单不可以修改
        {
            throw new RuntimeException("该订单不可以修改! 订单编号:"+ordervo.getOrderNo());
        }
        
        if (flag) {
            if (ordervo.getPlaceOrderDateTime()==null) {
                ordervo.setPlaceOrderDateTime(new Date(System.currentTimeMillis()));
            }
            
            HospitalVO hospitalVO=this.getHospitalByNo(ordervo.getHospitalNo());
            ordervo.setHospitalName(hospitalVO.getName());
            ordervo.setSaleNo(hospitalVO.getSalesmanNo());
            ordervo.setSaleName(hospitalVO.getSalesmanName());
            //如果是已保存的订单修改时提交了,则状态改为已提交
            if(ordervo.getStatus()==0){
                ordervo.setStatus(1);
            }else{
                ordervo.setStatus(order.getStatus());
            }
            log.info(ordervo.toString());
            orderDAO.updateVO(ordervo);
        }
        else {
            throw new RuntimeException("对不起,你没有权限修改该订单! 订单编号:"+ordervo.getOrderNo());
        }
        
    }



我更新都是从页面拿到订单编号后从数据库中把po取出来后对对应的vo进行更新的,按道理不应该报这个错啊,

实在是费解,求帮助!

举报
魔术念
发帖于4年前 0回/10K+阅
顶部