Mybatis executes Update and returns a negative number of rows. mybatisupdate
Obtain the number of update rows of mybatis. A negative number is always returned. Later, I found the reason on the official website because of defaultExecutorType. defaultExecutorType has three executors SIMPLE, REUSE, and BATCH. Among them, BATCH can update the cache SQL statement in batches to improve the performance. However, a defect is that the number of rows returned by update and delete cannot be obtained. The default executor of defaultExecutorType is SIMPLE.
Name |
Description |
SIMPLE |
Execute other statements by the executor |
REUSE |
The prepared statements statement may be used repeatedly. |
BATCH |
Statement execution and batch update |
Because the BATCH executor is enabled in the project configuration, the number of rows returned by the UPDATE and DELETE operations is lost. Change the executor 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> <! -- Enable cache for global mapper --> <setting name = "cacheEnabled" value = "true"/> <! -- Disable instant loading of correlated objects during query to improve performance --> <setting name = "lazyLoadingEnabled" value = "true"/> <! -- Set the join object loading mode. Here, the field is loaded as needed (the loading field is determined by the SQL statement), and all fields in the join table are not loaded, to improve performance --> <setting name = "aggressiveLazyLoading" value = "false"/> <! -- For unknown SQL queries, different result sets can be returned to achieve common results --> <setting name = "multipleResultSetsEnabled" value = "true"/> <! -- You can use a column label to replace the column name --> <setting name = "useColumnLabel" value = "true"/> <! -- Allow the use of custom primary key values (for example, the UUID 32-bit code generated by the program as the key value ), the primary key generation policy of the data table will be overwritten --> <setting name = "useGeneratedKeys" value = "true"/> <! -- Support field-attribute ing for nested resultMap --> <setting name = "autoMappingBehavior" value = "FULL"/> <! -- Cache SQL for batch update operations to improve performance --> <! -- DefaultExecutorType is set to BATCH. A defect is that the number of rows returned by update and delete cannot be obtained. --> <! -- <Setting name = "defaultExecutorType" value = "BATCH"/> --> <! -- Timeout when the database does not respond for more than 25000 seconds --> <setting name = "defaultStatementTimeout" value = "25000"/> <! -- Log --> <! -- <Setting name = "logImpl" value = "SLF4J"/> --> </settings> <! -- Register the mybatis plugin --> <plugins> <! -- Mysql paging plug-in --> <plugin interceptor = "com. rvho. mybatis. interceptor. mybatisPageInterceptor "> <property name =" databaseType "value =" mysql "/> </plugin> </plugins> </configuration>
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.