So I am trying to do a batch insert using MyBatis below is my xml mapper
<insert id="insertMessages" parameterType="java.util.List">
INSERT INTO Messages(user, id, month,
key, value, name,
message, dateCreated, createdBy)
VALUES
<foreach item="item" collection="list" open="(" separator="),(" close=")">
#{item.user},
#{item.id},
#{item.month},
#{item.key},
#{item.value},
#{item.name},
#{item.message},
GETDATE(),
#{item.createdBy}
</foreach>
</insert>
right now it only works when the batch size is 200 or less. Anything more than 200, gets the error :
-The incoming tabular data stream(TDS) remote procedure call (RPC) protocol stream is incorrect.Too many parameters provided in the RPC request.The maximum is 2100
which is caused by SQL server not being able to take more than 2100 paramerters and myBatis builds query with "?" and then passes parameters to the query. In my case it is 8 parameters so if batch is 300 then 2400 parameters will be passed to DB. So I can keep adjusting the batch insert size for inserts but there's probably a better way. What can I do to not hit this parameters limitation on SQL server side? without changing SQL server. Thanks!