alibaba/spring-cloud-alibaba · error · BusinessException
no enough balance
Error message
no enough balance
What it means
Thrown by the private checkBalance helper inside AccountServiceImpl.reduceBalance. It reads the current money via accountMapper.getBalance(userId) and throws BusinessException("no enough balance") when balance < price. This is the explicit pre-flight balance check that runs before the deducting UPDATE. Note: balance is an Integer from the DB; if the userId has no row, getBalance returns null and the comparison `balance < price` throws NullPointerException instead of this message.
Source
Thrown at spring-cloud-alibaba-examples/integrated-example/integrated-account/src/main/java/com/alibaba/cloud/integration/account/service/impl/AccountServiceImpl.java:70
int updateCount = accountMapper.reduceBalance(userId, price, updateTime);
if (updateCount == 0) {
throw new BusinessException("reduce balance failed");
}
}
@Override
public Result<?> getRemainAccount(String userId) {
Integer balance = accountMapper.getBalance(userId);
if (balance == null) {
return Result.failed("wrong userId,please check the userId");
}
return Result.success(balance);
}
private void checkBalance(String userId, Integer price) throws BusinessException {
Integer balance = accountMapper.getBalance(userId);
if (balance < price) {
throw new BusinessException("no enough balance");
}
}
}
View on GitHub (pinned to 115d590110)
Solutions
- Inspect/raise the account row money: UPDATE account SET money = <larger value> WHERE user_id = '<userId>'.
- Reduce the order count so count*2 stays within the available balance.
- Confirm the userId matches a seeded account row to avoid the separate NullPointerException path.
Example fix
// before
private void checkBalance(String userId, Integer price) throws BusinessException {
Integer balance = accountMapper.getBalance(userId);
if (balance < price) {
throw new BusinessException("no enough balance");
}
}
// after: guard the null case to avoid an NPE masking the real cause
private void checkBalance(String userId, Integer price) throws BusinessException {
Integer balance = accountMapper.getBalance(userId);
if (balance == null) {
throw new BusinessException("account not found: " + userId);
}
if (balance < price) {
throw new BusinessException("no enough balance");
}
} Defensive patterns
Strategy: validation
Validate before calling
// Validate funds before deducting, and guard null to avoid a hidden NPE.
Integer balance = accountMapper.getBalance(userId);
if (balance == null || balance < price) {
// surface a clear 'insufficient funds' / 'no account' result instead of deducting
} Prevention
- Always null-check Integer results from mappers before comparison.
- Seed account money so count*2 (the order price) is affordable.
- Expose a getBalance-style endpoint for clients to pre-check funds.
When it happens
Trigger: reduceBalance(userId, price) called with a price larger than the account's current money (e.g., order quantity * unit price exceeds funds). Reached from the order service when accountService.reduceBalance is invoked after stock deduction.
Common situations: Account table seeded with too little money for the demo (e.g., money=0 or a small value); a test that orders more units than the balance covers; price computed as count*2 in OrderServiceImpl exceeding the seeded balance.
Related errors
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/aa1464a394ccf624.
Report an issue: GitHub.