Gets the number of update rows for the MyBatis and always returns negative numbers. Later on the official network to find the reason, is due to Defaultexecutortype, Defaultexecutortype has three actuators simple, reuse and batch. Where batch can cache SQL for bulk update operations to improve performance, there is a flaw in the inability to get update, the number of rows returned by delete. The default actuator for Defaultexecutortype is simple.
name |
Description |
Simple |
Actuators Execute other statements |
Reuse |
Prepared statements statements may be used repeatedly |
BATCH |
Statements and batch updates can be executed repeatedly |
Because batch executor is enabled in the project configuration, the number of rows returned by update and delete is lost, and the actuator is changed to simple.
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE configuration Public "-//mybatis.org//dtd Config 3.0//en" "Http://mybatis.org/dtd/mybatis-3-config.dtd" > <configuration> <settings> <!--Global Mapper Enable cache -- <setting name="cacheenabled" value="true" /> < when!--query, close the associated object for immediate loading to improve performance-- <setting name="lazyloadingenabled" value="true" / > <!--Set the shape of the associated object load, where the field is loaded on demand (the Load field is specified by SQL) and all fields of the associated table are not loaded to improve performance -- <setting name="aggressivelazyloading" value="false" /> <!--for unknown SQL queries, allowing different result sets to be returned to achieve a common effect-- <setting name="multipleresultsetsenabled" value="true" /> <!--allow column labels to be used instead of column names -- <setting name="Usecolumnlabel" value="true" /> <!--allows you to use a custom primary key value (such as a program-generated UUID 32-bit encoding as the key value), and the PK generation strategy for the data table will be overwritten - <setting name="Usegeneratedkeys" value="true" /> <!--given nested resultmap with field-property mapping support- <setting name="Automappingbehavior" value="full" / > <!--cache SQL for bulk update operations to improve performance -- <!--Defaultexecutortype set to batch has a flaw in the inability to get update, the number of rows returned by Delete-- <!--<setting name= "Defaultexecutortype" value= "BATCH"/>--> <!--The database is still not responding for more than 25,000 seconds timeout - <setting name="Defaultstatementtimeout" value="25000" /> <!--Log --- <!--<setting name= "Logimpl" value= "slf4j"/> -- </Settings> <!--register MyBatis plugins-- <plugins> <!--mysql Paging plugin-- <plugin Interceptor="Com.rvho.mybatis.interceptor.MybatisPageInterceptor"> < property name="DatabaseType" value="mysql"/> </plugin> </plugins></configuration>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MyBatis execution Update Returns a negative number of rows