Mybatis:update、delete、insert操作返回-2147482646

一、解决方案:

产生此现象的原因是因为mybatis配置文件中的这样一个配置

<!-- 配置一个可以执行批量的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>

其中,可以看到executorType配置的值是BATCH,改为SIMPLE即可正确返回数据库受影响的行数

二、贸然在项目中修改会不会产生问题

  • Mybatis内置的ExecutorType有3种,默认的是simple,该模式下它为每个语句的执行创建一个新的预处理语句,单条提交sql;而batch模式重复使用已经预处理的语句
  • 在测试中使用simple模式提交10000条数据,时间为18248 毫秒,batch模式为5023 ,性能提高70%
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章