收到的请求参数过多。

huangapple go评论76阅读模式
英文:

The incoming request has too many parameters

问题

我在使用 Hibernate 执行 SELECT 查询时遇到了以下异常:SQLServerException: 入站请求的参数过多。服务器支持最多 2100 个参数。请减少参数数量并重新发送请求。。以下是我的查询语句:收到的请求参数过多。

有人知道在 Hibernate 中有解决这个问题的方法吗?
非常感谢任何帮助,谢谢!

英文:

I have the following exception SQLServerException: The incoming request has too many parameters. The server supports a maximum of 2100 parameters. Reduce the number of parameters and resend the request. while executing SELECT query via Hibernate.
Here is my query 收到的请求参数过多。

Does anybody know any solutions for this in Hibernate?
Will be very grateful for any help, thank you!

答案1

得分: 1

作为对这个问题的解决方法,可以将数据分块获取。

List<List<Long>> partitions = new ArrayList<List<Long>>();
List<Long> bucket = new ArrayList<>();
int count = 0;
for (Long id : ids) {
    count++;
    if (count > 1000) {
        count = 1;
        partitions.add(bucket);
        bucket = new ArrayList<>();
    }
    partitions.add(bucket);
}
List<PreStagePaymentData> data = new ArrayList<>();
List<PreStagePaymentData> temp;
for (List<Long> partition : partitions) {
    temp = findPreStageDataByPaymentIds(partition);
    data.addAll(temp);
}
英文:

As a workaround for this issue would be to get data in chunks.

List&lt;List&lt;Long&gt;&gt; partitions = new ArrayList&lt;List&lt;Long&gt;&gt;();
List&lt;Long&gt; bucket = new ArrayList&lt;&gt;();
int count = 0;
for(Long id : ids){
count++;
if(count&gt;1000){
count = 1;
partitions.add(bucket);
bucket = new ArrayList&lt;&gt;();
}
partitions.add(bucket);
}
List&lt;PreStagePaymentData&gt; data= new ArrayList&lt;&gt;();
List&lt;PreStagePaymentData&gt; temp;
for(List&lt;Long&gt; partition : partitions){
temp = findPreStageDataByPaymentIds(partition);
data.addAll(temp);
}

huangapple
  • 本文由 发表于 2020年9月28日 21:59:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/64103701.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定