springMVC+mybatis 增删该操作后判断影响行数一直返回-2147482646


MyBatis发现更新和插入返回值一直为"-2147482646"的错误是由defaultExecutorType设置引起的,如果设置为BATCH,更新返回值就会丢失。mybatis官方的讨论列表,这句很关键:“If the BATCH 
executor is in use, the update counts are being lost. ”

在我的springMVC和mybatis整合中设置了如下内容
    <!-- 配置mapper接口 -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="*****.dao" />
    </bean>
    <bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactory" />
        <constructor-arg index="1" value="BATCH" />
    </bean>
    <!-- 事务配置 -->
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

就是因为上面设置了 <constructor-arg index="1" value="BATCH" /> 这句引起的。去掉即可。

由于框架是别人搭建的,不知道此处的设置是何用意。

<constructor-arg index="1" value="BATCH" />这是设置如此是想要进行批量操作,但是经测试没有此处的设置也可进行批量操作。大胆果断的删除即可。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM