我得到下面的错误,而试图插入Azure Table中存储多个实体:Azure的批量插入:错误的请求错误
com.microsoft.azure.storage.table.TableServiceException: Bad Request
at com.microsoft.azure.storage.table.TableBatchOperation$1.postProcessResponse(TableBatchOperation.java:525)
at com.microsoft.azure.storage.table.TableBatchOperation$1.postProcessResponse(TableBatchOperation.java:433)
at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:146)
下面是批量插入Java代码:
public BatchInsertResponse batchInsert(BatchInsertRequest request){
BatchInsertResponse response = new BatchInsertResponse();
String erpName = request.getErpName();
HashMap<String,List<TableEntity>> tableNameToEntityMap = request.getTableNameToEntityMap();
HashMap<String,List<TableEntity>> errorMap = new HashMap<String,List<TableEntity>>();
HashMap<String,List<TableEntity>> successMap = new HashMap<String,List<TableEntity>>();;
CloudTable cloudTable=null;
for (Map.Entry<String, List<TableEntity>> entry : tableNameToEntityMap.entrySet()){
try {
cloudTable = azureStorage.getTable(entry.getKey());
} catch (Exception e) {
e.printStackTrace();
}
// Define a batch operation.
TableBatchOperation batchOperation = new TableBatchOperation();
List<TableEntity> value = entry.getValue();
for (int i = 0; i < value.size(); i++) {
TableEntity entity = value.get(i) ;
batchOperation.insertOrReplace(entity);
if (i!=0 && i % batchSize == 0) {
try {
cloudTable.execute(batchOperation);
batchOperation.clear();
} catch (Exception e) {
e.printStackTrace();
}
}
}
try {
cloudTable.execute(batchOperation);
} catch (Exception e) {
e.printStackTrace();
}
}
}
以上代码工作正常,如果我将分配batchSize值为10,但如果我将分配给1000或100它会抛出错误的请求错误。
请帮我解决这个错误。我正在使用Spring引导和Azure存储Java SDK 4.3.0版。
通常400错误意味着您的某个属性的值有问题。找出的一种方法是通过Fiddler跟踪请求/响应并查看正在发送的实际数据。有可能有一些数据类型不匹配。 – Aravind
e.RequestInformation.HttpStatusMessage将为您提供失败的确切原因 – yonisha
@Aravind我认为数据是正确的,因为我可以通过设置batchSize = 10来插入相同的数据。 – Sunil