Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the error report of MyBatis splicing batch SQL statement execution

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to solve MyBatis splicing batch SQL statement execution error". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian to study and learn "MyBatis splicing batch SQL statement execution error" together.

Download server basic business data for local batch insertion operation. Since mybatis is used for persistence operation in the project, the batch insertion function of mybatis is directly considered.

1. Here is some code for the Mapper interface

public interface PrintMapper{@InsertProvider(type = PrintMapperProvider.class,method = "insertAllLotWithVehicleCode4H2") void insertAllLotWithVehicleCode(List lotWithVehicleCodes);}

2. Corresponding to function fragment in MapperProvider

public String insertAllLotWithVehicleCode4H2(Map map){List lotWithVehicleCodeBOs = map.get("list");StringBuilder sb = new StringBuilder("INSERT INTO MTC_LOT_WITH_VEHICLE_CODE (LOT_CODE,PRODUCT_VEHICLE_CODE) VALUES ");MessageFormat messageFormat = new MessageFormat("(" +"#'{'list[{0}].lotCode }," +"#'{'list[{0}].productVehicleCode }" +")"); int size = lotWithVehicleCodeBOs.size(); for (int i = 0; i

< size; i++){sb.append(messageFormat.format(new Object[]{i})); if (i < size - 1) sb.append(",");} return sb.toString();} 3.service层 @Transactionalpublic void synchLotWithVehicleCodeToLocalDB(List lotWithVehicleCodeBOs){ if(null != lotWithVehicleCodeBOs && lotWithVehicleCodeBOs.size()>

0){printMapper.insertAllLotWithVehicleCode(lotWithVehicleCodeBOs);}}

No problems occurred when the program went online. When the business volume soared, the program began to report errors when more than 500 items were executed at the same time:

Caused by: org.apache.ibatis.builder.BuilderException: Improper inline parameter map format. Should be: #{propName,attr1=val1,attr2=val2}at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.buildParameterMapping(SqlSourceBuilder.java:89)at org.apache.ibatis.builder.SqlSourceBuilder$ParameterMappingTokenHandler.handleToken(SqlSourceBuilder.java:43)at org.apache.ibatis.parsing.GenericTokenParser.parse(GenericTokenParser.java:25)at org.apache.ibatis.builder.SqlSourceBuilder.parse(SqlSourceBuilder.java:24)at org.apache.ibatis.builder.annotation.ProviderSqlSource.createSqlSource(ProviderSqlSource.java:57)... 61 more

Exception indicates SQL statement build problem, DEBUG goes in:

Root cause:

MessageFormat messageFormat = new MessageFormat("(" +"#'{'list[{0}].lotCode }," +"#'{'list[{0}].productVehicleCode }," +")");int size = lotWithVehicleCodeBOs.size();for (int i = 0; i < size; i++){ sb.append(messageFormat.format(new Object[]{i})); if (i

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report