我想再问下 ,再service层下调用 两个dao层的数据插入的方法 ,现在我测试事务回滚 ,第一个dao 层插入数据库成功的 ,第二个插入数据库是不成功的 ,为什么事务没有回滚?
这个业务逻辑层的代码  Java code
public String saveParam(EuserComm euserComm, Bp[] bp, Temp[] temps, Bo[] bo) {
        if(bp==null||bp.length==0){
            throw new RuntimeException("RC002");
        }
        BpPojo[] bpList=new BpPojo[bp.length];
        for(int i=0;i<bp.length;i++){
            BpPojo bpPojo=new BpPojo();
            Bp bpObj=bp[i];
            bpPojo.setBpId(UUIDGenerator.getUUID());
            bpPojo.setRegisterId(bpObj.getRegisterId());
            bpPojo.setUserName(userDao.getUserNameByRegId(bpObj.getRegisterId()));
            bpPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm", bpObj.getMeasureTime()));
            bpPojo.setProductNo(euserComm.getProductNo());
            bpPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm", euserComm.getSendTime()));
            bpPojo.setSp(bpObj.getSp());
            bpPojo.setDp(bpObj.getDp());
            int pp=bp[i].getSp()-bp[i].getDp();
            bpPojo.setPp(pp);
            bpList[i]=bpPojo;
        }
        bpDao.saveBp(bpList);
        
        if(temps==null||temps.length==0){
            throw new RuntimeException("RC002");
        }
        TempPojo[] tempList=new TempPojo[temps.length];
        String userName=userDao.getUserNameByRegId(temps[0].getRegisterId());
        for(int i=0;i<temps.length;i++){
            TempPojo tempPojo=new TempPojo();
            Temp temp=temps[i];
            tempPojo.setTempId(UUIDGenerator.getUUID());
            tempPojo.setRegisterId(temp.getRegisterId());
            tempPojo.setProductNo(euserComm.getProductNo());
            tempPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm",euserComm.getSendTime()));
            tempPojo.setUserName(userName);
            tempPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm",temp.getMeasureTime()));
            tempPojo.setTempValue(Float.parseFloat(temp.getTempValue()));
            tempList[i]=tempPojo;            
        }
        tempDao.saveTemp(tempList);
        
        return "RC001";
    }
[/code]

解决方案 »

  1.   

    我觉得是ibatis的bug
    后来通过Spring的AOP切入解决
      

  2.   

    不是这个原因 ,Spring的AOP切入 配置是正确的 ,没有抛出异常是可以 插入到数据库中的,现在是我 测试事务回滚 ,所以特意抛出异常 ,但是事务没有回滚 ,还是一张表中插入了数据 
      

  3.   

    我在spring配置文件中配置了 ,<!-- 配置哪些类哪些方法使用事务 -->
    <bean id="transactionManager_Apprsal"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource_apprsal"></property>
    </bean>
    <tx:advice id="txAdvice_Apprsal"  transaction-manager="transactionManager_Apprsal">
    <tx:attributes>
    <tx:method name="login" propagation="REQUIRED" />
    <tx:method name="signOut" propagation="REQUIRED" />
    <tx:method name="create*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="save*" propagation="REQUIRED"  rollback-for="Throwable"/>
    <tx:method name="insert*" propagation="REQUIRED"/>
    <tx:method name="delete*" propagation="REQUIRED"/>
    <tx:method name="add*" propagation="REQUIRED"/>
    <tx:method name="copy*" propagation="REQUIRED"/>
    <tx:method name="getSerial" propagation="REQUIRED"/>
    <!-- tx:method name="*" read-only="true" /-->
    </tx:attributes>
    </tx:advice>
    <aop:config>
    <aop:pointcut id="allDAO_Apprsal"
    expression="execution(* com.easepal..service.impl.*SerivceImpl.*(..))" />
    <aop:advisor advice-ref="txAdvice_Apprsal" pointcut-ref="allDAO_Apprsal" />
    </aop:config>
    怎么还有手动回滚 ,若有手动回滚 ,又是怎样写的 
      

  4.   

    帮你顶下吧,期待高人的解决
    你自己用JDBC写个简单的事务型操作吧,MYSQL数据库默认就好像不支持事务操作,如果你解决了问题麻烦发下方案俺也学习下
      

  5.   

    service里面有么有把异常catch掉了。
      

  6.   


    public String saveParam(EuserComm euserComm, Bp[] bp, Temp[] temps, Bo[] bo) {
    try{if(bp==null||bp.length==0){
      throw new RuntimeException("RC002");
      }
      BpPojo[] bpList=new BpPojo[bp.length];
      for(int i=0;i<bp.length;i++){
      BpPojo bpPojo=new BpPojo();
      Bp bpObj=bp[i];
      bpPojo.setBpId(UUIDGenerator.getUUID());
      bpPojo.setRegisterId(bpObj.getRegisterId());
      bpPojo.setUserName(userDao.getUserNameByRegId(bpObj.getRegisterId()));
      bpPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm", bpObj.getMeasureTime()));
      bpPojo.setProductNo(euserComm.getProductNo());
      bpPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm", euserComm.getSendTime()));
      bpPojo.setSp(bpObj.getSp());
      bpPojo.setDp(bpObj.getDp());
      int pp=bp[i].getSp()-bp[i].getDp();
      bpPojo.setPp(pp);
      bpList[i]=bpPojo;
      }
      bpDao.saveBp(bpList);
        
      if(temps==null||temps.length==0){
      throw new RuntimeException("RC002");
      }
      TempPojo[] tempList=new TempPojo[temps.length];
      String userName=userDao.getUserNameByRegId(temps[0].getRegisterId());
      for(int i=0;i<temps.length;i++){
      TempPojo tempPojo=new TempPojo();
      Temp temp=temps[i];
      tempPojo.setTempId(UUIDGenerator.getUUID());
      tempPojo.setRegisterId(temp.getRegisterId());
      tempPojo.setProductNo(euserComm.getProductNo());
      tempPojo.setSendTime(StringUtil.dateFormat("yyyyMMddHHmm",euserComm.getSendTime()));
      tempPojo.setUserName(userName);
      tempPojo.setMeasureTime(StringUtil.dateFormat("yyyyMMddHHmm",temp.getMeasureTime()));
      tempPojo.setTempValue(Float.parseFloat(temp.getTempValue()));
      tempList[i]=tempPojo;   
      }
      tempDao.saveTemp(tempList);
        
      return "RC001";
      }
    catch(Exception e){  
       ........

    <tx:method name="save*" propagation="REQUIRED"  rollback-for="Exception"/>
    还是不行的话,看下面这个表达式错了没 <aop:pointcut id="allDAO_Apprsal"
                expression="execution(* com.easepal..service.impl.*SerivceImpl.*(..))" />