在使用MyBatis-Generator自动生成的代码进行删除数据时( deleteByPrimaryKey 方法 )返回的int 值为 -2147482646 。正常的逻辑是成功删除返回 1 ,失败返回 0(未删除数据) ,特意去官网看了这个方法的说明,发现没有类似的说明(我没看到…)。
以下为其他网友的解决方案,还果然是这一原因。。以下内容为转载
作者:就算曾经遍体鳞伤也要相信明天
来源:优快云
原文:https://blog.youkuaiyun.com/u010177899/article/details/68061303
版权声明:本文为博主原创文章,转载请附上博文链接!
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" />这是设置如此是想要进行批量操作,但是经测试没有此处的设置也可进行批量操作。大胆果断的删除即可。

博客详细解析了在使用MyBatis时遇到更新和插入操作返回-2147482646的问题,并提供了具体的解决方案。问题源于defaultExecutorType设置为BATCH,导致更新计数丢失。通过调整此设置,可以恢复正常的数据操作反馈。
1659

被折叠的 条评论
为什么被折叠?



