paascloud/paascloud-master · error · OmcBizException
OMC10031014
OMC10031014
Error message
OMC10031014
What it means
OMC10031014 maps to ErrorCodeEnum OMC10031014 ("更新购物车数据失败, cartId=%s" — failed to update cart data for the given cartId). In OmcCartServiceImpl.saveCart's update path, when the cart item already exists the code merges quantities and calls omcCartMapper.updateByPrimaryKeySelective; if the update affects fewer than 1 row, an OmcBizException is thrown with the existing cart's id. It indicates the UPDATE statement did not persist — the row vanished mid-transaction, a concurrent delete won the race, or a DB error occurred.
Solutions
- Retry the operation once: re-read the cart row (selectByPrimaryKey on omcCartExist.getId()); if it no longer exists, insert a new row instead of failing.
- Serialize cart updates per user (distributed lock or SELECT ... FOR UPDATE on the omc_cart row) to avoid concurrent update/delete races.
- Enable SQL logging and check the mapper XML/update statement for conditions (e.g. optimistic-lock version or wrong key) that could match 0 rows.
- Check the database error log for a swallowed exception or rollback around the update.
- If the delete was intentional, treat the missing row as success/idempotent rather than throwing.
Example fix
// before
int updateResult = omcCartMapper.updateByPrimaryKeySelective(omcCart);
if (updateResult < 1) {
throw new OmcBizException(ErrorCodeEnum.OMC10031014, omcCartExist.getId());
}
// after
int updateResult = omcCartMapper.updateByPrimaryKeySelective(omcCart);
if (updateResult < 1) {
logger.warn("购物车更新未命中, 可能已被并发删除, 重新插入, cartId={}", omcCartExist.getId());
omcCart.setId(null);
omcCartMapper.insertSelective(omcCart);
} Defensive patterns
Strategy: retry
Validate before calling
OmcCart existing = omcCartMapper.selectByPrimaryKey(omcCartExist.getId());
if (existing == null) {
// row already deleted concurrently — insert a fresh cart row instead of updating
omcCartMapper.insertSelective(omcCart);
return;
} Type guard
boolean canUpdate(OmcCart existing) { return existing != null && existing.getId() != null; } Try / catch
try {
cartService.updateCartList(loginUser, list);
} catch (OmcBizException e) {
if (String.valueOf(e.getMessage()).contains("更新购物车数据失败")) {
// re-read the cart row and retry once with fresh state
} else { throw e; }
} Prevention
- Lock cart rows per user during updates (SELECT ... FOR UPDATE or a distributed lock).
- Check affected-row counts and reconcile with a re-read before throwing.
- Enable SQL logging to catch 0-row updates caused by mismatched WHERE conditions.
- Make cart add/update idempotent so concurrent requests converge instead of failing.
When it happens
Trigger: Adding to an existing cart item (omcCartExist != null) but omcCartMapper.updateByPrimaryKeySelective returns 0 — e.g. the row was deleted by a concurrent request between the select and the update, the id is stale, or the database rejected/rolled back the update.
Common situations: Two tabs/devices updating the same cart simultaneously and one deletes the item; a background job cleared the cart during checkout; DB connection or constraint failure silently reducing the affected-row count; replica/primary lag with stale omcCartExist data.
Related errors
AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10).
Data as JSON: /api/errors/f6e62aee41738c1f.
Report an issue: GitHub.
Appendix: source
Thrown at paascloud-provider/paascloud-provider-omc/src/main/java/com/paascloud/provider/service/impl/OmcCartServiceImpl.java:187
Long userId = authDto.getUserId();
Preconditions.checkArgument(productId != null, "货品ID不能为空");
Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
omcCart.setUpdateInfo(authDto);
OmcCart omcCartExist = omcCartMapper.selectByProductIdAndUserId(productId, userId);
if (PublicUtil.isEmpty(omcCartExist)) {
try {
omcCartMapper.insertSelective(omcCart);
} catch (Exception e) {
logger.error("新增购物车, 出现异常={}", e.getMessage(), e);
}
return;
}
omcCart.setId(omcCartExist.getId());
omcCart.setQuantity(omcCart.getQuantity() + omcCartExist.getQuantity());
int updateResult = omcCartMapper.updateByPrimaryKeySelective(omcCart);
if (updateResult < 1) {
throw new OmcBizException(ErrorCodeEnum.OMC10031014, omcCartExist.getId());
}
}
@Override
public int saveCart(Long userId, Long productId, int count) {
logger.info("saveCart - 保存购物车记录 userId={}, productId={}, count={}", userId, productId, count);
Preconditions.checkArgument(userId != null, ErrorCodeEnum.UAC10011001.msg());
Preconditions.checkArgument(productId != null, ErrorCodeEnum.MDC10021021.msg());
Preconditions.checkArgument(count != 0, "数量不符");
int resultInt = 0;
OmcCart cart = this.getCartByUserIdAndProductId(userId, productId);
if (cart == null) {
cart = new OmcCart();
cart.setQuantity(count);
cart.setChecked(OmcApiConstant.Cart.CHECKED);View on GitHub (pinned to 781281a950)