{"record":{"id":"94a5c4f0d1344648","repo":"paascloud/paascloud-master","slug":"omc10031009","errorCode":"OMC10031009","errorMessage":"OMC10031009","messagePattern":"OMC10031009","errorType":"error_code","errorClass":"OmcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcOrderDetailServiceImpl.java","lineNumber":55,"sourceCode":"\t@Override\n\tpublic List<OmcOrderDetail> getListByOrderNoUserId(String orderNo, Long userId) {\n\t\tPreconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());\n\t\tPreconditions.checkArgument(StringUtils.isNotEmpty(orderNo), \"订单号不能为空\");\n\n\t\treturn omcOrderDetailMapper.getListByOrderNoUserId(orderNo, userId);\n\t}\n\n\t@Override\n\tpublic List<OmcOrderDetail> getListByOrderNo(String orderNo) {\n\t\tPreconditions.checkArgument(StringUtils.isNotEmpty(orderNo), \"订单号不能为空\");\n\t\treturn omcOrderDetailMapper.getListByOrderNo(orderNo);\n\t}\n\n\t@Override\n\tpublic void batchInsertOrderDetail(List<OmcOrderDetail> omcOrderDetailList) {\n\t\tint insertResult = omcOrderDetailMapper.batchInsertOrderDetail(omcOrderDetailList);\n\t\tif (insertResult < omcOrderDetailList.size()) {\n\t\t\tthrow new OmcBizException(ErrorCodeEnum.OMC10031009);\n\t\t}\n\t}\n}","sourceCodeStart":37,"sourceCodeEnd":58,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcOrderDetailServiceImpl.java#L37-L58","documentation":"OMC10031009 means '批量插入订单明细失败' (batch insert of order details failed). batchInsertOrderDetail checks the number of rows the MyBatis mapper reports as inserted and throws if insertResult < omcOrderDetailList.size(), i.e. the batch write did not persist every order-detail row.","triggerScenarios":"omcOrderDetailMapper.batchInsertOrderDetail returns a row count smaller than the list size — partial batch failure, list containing rows violating DB constraints, or an empty/oversized batch hitting driver limits.","commonSituations":"DB constraint violations (null required columns, key collisions) on some rows; oversized batch exceeding max_allowed_packet or JDBC rewrite batch limits; connection issues mid-batch; calling the method with a list where the mapper silently skips entries.","solutions":["Inspect DB logs / enable SQL logging to find which rows failed and why (constraints, packet size).","Check that every OmcOrderDetail has required non-null fields (orderId, productId, userId, quantity, price) before the call.","Split very large batches into chunks (e.g. 500–1000 rows) to avoid packet/statement-size limits.","Ensure the method runs inside a transaction so a partial insert is rolled back, then retry the whole batch."],"exampleFix":"// before\nomcOrderDetailService.batchInsertOrderDetail(omcOrderDetailList);\n// after (chunked, defensive)\nif (CollectionUtils.isNotEmpty(omcOrderDetailList)) {\n    List<List<OmcOrderDetail>> chunks = Lists.partition(omcOrderDetailList, 500);\n    for (List<OmcOrderDetail> chunk : chunks) {\n        omcOrderDetailService.batchInsertOrderDetail(chunk);\n    }\n}","handlingStrategy":"try-catch","validationCode":"// Java, sanity-check inputs before batch insert\nif (CollectionUtils.isEmpty(omcOrderDetailList)) {\n    return; // nothing to insert, avoid misleading failure\n}\nfor (OmcOrderDetail d : omcOrderDetailList) {\n    if (d.getOrderId() == null || d.getProductId() == null || d.getUserId() == null) {\n        throw new IllegalArgumentException(\"Order detail missing required fields\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    omcOrderDetailService.batchInsertOrderDetail(omcOrderDetailList);\n} catch (OmcBizException e) {\n    if (e.getCode() == ErrorCodeEnum.OMC10031009.getCode()) {\n        logger.error(\"Batch order-detail insert incomplete, size={}\", omcOrderDetailList.size(), e);\n        throw new OmcBizException(ErrorCodeEnum.OMC10031009); // let @Transactional roll back\n    }\n    throw e;\n}","preventionTips":["Run batch inserts inside @Transactional so partial failures roll back cleanly.","Chunk large batches (≤500–1000 rows) to stay under DB packet limits.","Validate required fields on every row before inserting.","Enable SQL logging in staging to catch mapper row-count mismatches early."],"tags":["database","batch-insert","order-details","mybatis"],"backgroundTag":"database-write-failed","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}