Spring与Mybatis整合后批量新增执行成功但是数据没提交到数据库

Spring与Mybatis整合,在开发导入功能时,在Mybatis中增加了一个insertBath方法。

由于原项目的代码结构划分不是很清晰,左右操作都是放到Service下,新功能开发时,将代码结构做了细化,

导致在insert数据时,系统表象是执行成功,而却Mybatis打出的日志也显示成功,并且显示成功条数,但是在后台查看,数据库中并没有数据,从而进行了问题排查。

首先先到的是Mybatis事务没提交,但是在PLSQL中查看有没有存在没提交的事务,显示并没有待提交的事务。

后来想到可能是Spring事务管理配置中没有将新增代码的事务加进去:

原来是事务配置如下:

<!-- 配置Spring的事务管理器 -->
    <bean id="transactionManager" 
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 拦截器方式配置事务 -->
    <tx:advice id="transactionAdvice"
        transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="save*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="update*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="delete*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="remove*" propagation="REQUIRED"
                rollback-for="Exception" />
               
            <tx:method name="*" propagation="SUPPORTS" read-only="true" />
        </tx:attributes>
    </tx:advice>
 
    <aop:config>
        <aop:pointcut id="transactionPointcut" 
            expression="(execution(* com.xxx.xxx.xxx.*.*.*.service..*.*(..)))  or (execution(* com.xxx.xxx.framework.service.*.*(..))) or (execution(* com.xxx.xxx.*.*..service.*.*(..)))" />
        <aop:advisor pointcut-ref="transactionPointcut"  advice-ref="transactionAdvice" order="2"/>
    </aop:config>
 

原有事务配置中并没有新增结构的事务声明,需要将其加入:

<!-- 配置Spring的事务管理器 -->
    <bean id="transactionManager" 
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <!-- 拦截器方式配置事务 -->
    <tx:advice id="transactionAdvice"
        transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="insert*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="save*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="update*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="delete*" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="remove*" propagation="REQUIRED"
                rollback-for="Exception" />
                <tx:method name="execute" propagation="REQUIRED"
                rollback-for="Exception" />
                <tx:method name="process" propagation="REQUIRED"
                rollback-for="Exception" />
            <tx:method name="*" propagation="SUPPORTS" read-only="true" />
        </tx:attributes>
    </tx:advice>
 
    <aop:config>
        <aop:pointcut id="transactionPointcut" 
            expression="(execution(* com.xxx.xxx.xxx.*.*.*.service..*.*(..))) or (execution(* com.xxx.xxx.xxx.*.*.*.rule..*.*(..))) or (execution(* com.xxx.xxx.xxx.*.*.*.executer..*.*(..)))  or (execution(* com.xxx.xxx.framework.service.*.*(..))) or (execution(* com.ronhe.romp.*.*..service.*.*(..)))" />
        <aop:advisor pointcut-ref="transactionPointcut"  advice-ref="transactionAdvice" order="2"/>
    </aop:config>

 

重启系统,插入成功,这只是一个小问题排查的记录,如以后遇到类似情况可作为参考。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值