paascloud/paascloud-master · error · BusinessException

删除数据失败!

Error message

删除数据失败!

What it means

BaseService.batchDelete iterates a list and deletes each record via mapper.delete; if any single delete affects fewer than 1 row, it throws BusinessException("删除数据失败!") ("data delete failed"). It guards against silent no-op deletes, e.g. the record no longer exists in the database.

Solutions

  1. Verify the entities in the list carry valid, existing primary keys before calling batchDelete.
  2. Refresh the list from the DB to drop rows already deleted by other sessions.
  3. If idempotent bulk deletion is intended, catch BusinessException or switch to a single batch delete statement that tolerates missing rows.

Example fix

// before
service.batchDelete(staleList);
// after
List<T> existing = mapper.selectByExample(ids);
if (!existing.isEmpty()) {
    service.batchDelete(existing);
}
Defensive patterns

Strategy: try-catch

Validate before calling

for (T record : list) {
    if (record.getId() == null || mapper.selectByPrimaryKey(record.getId()) == null) {
        throw new IllegalStateException("record to delete does not exist: " + record.getId());
    }
}

Try / catch

try {
    service.batchDelete(list);
} catch (BusinessException e) {
    log.warn("some rows were already deleted, refreshing list");
    list = reloadFromDb(list);
}

Prevention

When it happens

Trigger: Calling batchDelete(list) where mapper.delete(record) returns 0 for any record — typically the row was already deleted, the primary/condition keys on the entity don't match a row, or the entity's id is null.

Common situations: Concurrent deletion by another request/transaction, deleting by an entity whose id was never set (mapper matches nothing), soft-delete setups where delete conditions no longer match, or stale UI data submitted twice.

Related errors


AI-assisted analysis of paascloud/paascloud-master@781281a950 (2026-09-10). Data as JSON: /api/errors/d23199b35c36b357. Report an issue: GitHub.

Appendix: source

Thrown at paascloud-common/paascloud-common-core/src/main/java/com/paascloud/core/support/BaseService.java:203

	public int deleteByKey(Object key) {
		return mapper.deleteByPrimaryKey(key);
	}

	/**
	 * Batch delete int.
	 *
	 * @param list the list
	 *
	 * @return the int
	 */
	@Override
	public int batchDelete(List<T> list) {
		int result = 0;
		for (T record : list) {
			int count = mapper.delete(record);
			if (count < 1) {
				logger.error("删除数据失败");
				throw new BusinessException("删除数据失败!");
			}
			result += count;
		}
		return result;
	}

	/**
	 * Select count by example int.
	 *
	 * @param example the example
	 *
	 * @return the int
	 */
	@Override
	public int selectCountByExample(Object example) {
		return mapper.selectCountByExample(example);
	}

View on GitHub (pinned to 781281a950)