微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MyBatis MapperProvider MessageFormat拼接批量SQL语句执行报错的原因分析及解决办法

最近在项目中有这么一段代码:下载服务器基础业务数据进行本地批量插入操作,因项目中使用mybatis进行持久化操作,故直接考虑使用mybatis的批量插入功能

代码

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

函数片段

rush:java;"> 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();
}

rush:java;"> @Transactionalpublic void synchLotWithVehicleCodetoLocalDB(List lotWithVehicleCodeBOs) { if(null != lotWithVehicleCodeBOs && lotWithVehicleCodeBOs.size()>0) { printMapper.insertAllLotWithVehicleCode(lotWithVehicleCodeBOs); } }

程序上线的时候没有发生问题,在业务量猛增的时候,大约同时执行500条以上的时候程序就开始报错:

rush:java;"> 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

异常已指明sql语句构建问题,DEBUG进去:

问题根源:

rush:java;"> 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达到3位数以上时构建出的message为:

rush:java;"> (#{list[1,000].lotCode },#{list[1,000].productVehicleCode })

解决办法:messageformat.format(new Object[]{i+""}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_no=&#39;LJCG001H&#39; THEN dbo.ELTPNAME(a.fw_nu) ELSE d.fm_name END),e.fw_state_nm,f.fw_rmk_nm
if not exists(select name from syscolumns where name=&#39;tod_no&#39; and id=object_id(&#39;iebo09d12&#39;)) alter table iebo09d12 add tod_no varchar(
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_nm,g.fa_name from LJSS007H a (nolock) Left join LJPA002H b (nolock) On a.pa_no =b.pa_no Left jo
要在 SQL Server 2019 中设置定时自动重启,可以使用 Windows 任务计划程序。下面是详细的步骤: 步骤一:创建批处理文件 打开记事本。 输入以下内容: net stop &quot;SQL Server (MSSQLSERVER)&quot; net start &quot;SQ
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的事务日志已满,导致数据库操作失败。要解决这个问题,可以按照以下步骤操作: 1. 备份事务日志首先,备份事务日志以释放空间: BACKUP LOG [EastRiver] TO DISK = N&#39;C:\Backup\East
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标识ID,若不知道怎么查询数据库的标识ID, 打开SQL Server management studio,点击工具。选择SQL Server Profiler。 登录,登录成功后,如果有个默认弹窗,先取消 新建追踪 命名
--最新的解决方法 --先创建用户帐户,不进行授权,然后通过下面的SQL语句将该用户帐户关联至对应的数据库用户。优点是避免了重新授权的操作。 USE tempdbEXEC sp_change_users_login &#39;Update_One&#39;, &#39;iemis&#39;, &#3
命令: ALTER TABLE 表名 add 列名 数据类型 default 默认值 not null 例如: ALTER TABLE LJEL005H add el_req int default 15 not null
declare @i int set @i=340 while @i&lt;415 begin set @i=@iʱ insert into LJWK007H select &#39;2024&#39;,&#39;28&#39;,&#39;9110&#39;,&#39;3PTSD621000000