springMVC+mybatis 增删改操作后判断影响行数一直返回-2147482646
来源:互联网 发布:响应式web前端优化 编辑:程序博客网 时间:2024/06/06 08:26
MyBatis发现更新和插入返回值一直为"-2147482646"的错误是由defaultExecutorType设置引起的,如果设置为BATCH,更新返回值就会丢失。mybatis官方的讨论列表,这句很关键:“If the BATCH executor is in use, the update counts are being lost. ”
spring/mybtis 配置文件
<!-- 配置扫描器,将mybatis接口的实现加入到ioc容器中 --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><!-- 扫描所有dao接口的实现,加入到IOC容器中 --><property name="basePackage" value="com.sevenisland.dao"></property></bean><!-- 配置可以执行批量的sqlSession --><bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"><constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg><constructor-arg name="executorType" value="BATCH"></constructor-arg></bean><!-- Spring配置文件的核心点(数据源/与mybatis整合/事务控制) --><!-- 开启基于注解的事务,使用xml配置形式的事务(主要都是使用配置式) --><!-- 事务控制的配置 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><!-- 控制数据源 --><property name="dataSource" ref="dataSource"></property></bean>
在mybatis里面有一个配置属性defaultExecutorType,当这个值为BATCH时, 返回结果就只有-2147482646 这一个值。defaultExecutorType一共有三个值:BATCH, REUSE, SIMPLE。这三个值分别的特点如下:
名称 描述
SIMPLE 执行器执行其它语句,默认值。
REUSE 可能重复使用prepared statements 语句
BATCH 可以重复执行语句和批量更新
而解决以上问题的方法就是可以将defaultExecutorType的值改成SIMPLE或REUSE,或者直接删除该配置就可以了。
就是因为上面设置了 <constructor-arg name="executorType" value="BATCH"></constructor-arg> 这句引起的。去掉即可。
<constructor-arg name="executorType" value="BATCH"></constructor-arg>这是设置如此是想要进行批量操作,但是经测试没有此处的设置也可进行批量操作。大胆果断的删除即可。
参考地址:http://www.cnblogs.com/parryyang/p/5484459.html
阅读全文
0 0
- springMVC+mybatis 增删改操作后判断影响行数一直返回-2147482646
- springMVC 接收数组参数,springMVC mybatis批量增删改操作
- springmvc-mybatis的增删改查以及主键返回
- mybatis增删改操作无法返回操作数量的问题
- mybatis增删改操作
- mybatis-springmvc+mybatis实现增删改查
- easyui-datagrid行数据增删改操作
- mybatis进行增删改操作
- mybatis 增删改查操作
- Mybatis增删查改操作
- C#判断sql返回受影响行数
- SpringMVC+Mybatis整合的增删改查
- SpringMVC+Mybatis整合的增删改查
- springmvc mybatis 增删改查示例
- 【Mybatis】Mybatis增删改查操作
- mybatis+springMVC对新闻的增删改查操作(查询分页)
- Springmvc+mybatis案列 2(实现员工增删改查的操作,工具myeclipse)
- MyBatis连接DB2增删改查操作
- 从并发视角来看智能合约(下)【渡鸦论文系列】
- 推荐一些值得订阅的 Android 技术专栏
- 颠覆互联网中介模式,他们想通过超级虚拟主机创建开源的商业系统
- 英年早逝的不止ICO,我们可能失去更多
- 从并发视角来看智能合约(上)【渡鸦论文系列】
- springMVC+mybatis 增删改操作后判断影响行数一直返回-2147482646
- Android第三方库——SpinKitView样式
- jQuery之remove和empty事件
- 【word2vec实例2】加载模型
- CalendarView功能与用法(日历视图)
- 软件好,才是真的好:区块链的1976—2017
- 常用Java静态代码分析工具的分析与比较
- STL基本容器的使用
- 卡尔曼/扩展卡尔曼滤波器的原理及应用