OtterMind/Chat2DB · error · BusinessException
truncate table error
truncate table error
Error message
truncate table error
What it means
Thrown by DbTableServiceImpl.truncateTable to wrap any Exception from the truncate path (metaDataName resolution + dbManager.truncateTable SQL + executor.execute). It carries the cause and e.getMessage() as an arg. NOTE: the code is the literal 'truncate table error' (with spaces), NOT a defined i18n key, so the rendered message is the raw 'truncate table error : no message.' and the underlying DB error text is not shown to the user.
Source
Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbTableServiceImpl.java:312
DefaultSQLExecutor.getInstance().execute(connection, sql, resultSet -> null);
} catch (Exception e) {
log.error("drop table error", e);
throw new BusinessException("drop table error", new Object[]{e.getMessage()}, e);
}
}
@Override
public void truncateTable(DbTableQueryRequest param) {
try {
IDbMetaData metaData = Chat2DBContext.getDbMetaData();
Connection connection = Chat2DBContext.getConnection();
String name = metaData.getMetaDataName(param.getTableName());
String sql = Chat2DBContext.getDbManager()
.truncateTable(connection, param.getDatabaseName(), param.getSchemaName(), name);
DefaultSQLExecutor.getInstance().execute(connection, sql, resultSet -> null);
} catch (Exception e) {
log.error("truncate table error", e);
throw new BusinessException("truncate table error", new Object[]{e.getMessage()}, e);
}
}
@Override
public void copyTable(DbTableCopyRequest param) {
try {
IDbMetaData metaData = Chat2DBContext.getDbMetaData();
String newName = param.getNewName();
if (StringUtils.isBlank(newName)) {
newName = param.getTableName() + "_copy_" + DateUtil.format(new Date(), "MMddHHmmss");
if (newName.length() > 32) {
newName = newName.substring(0, 32);
}
}
String tableName = metaData.getMetaDataName(param.getTableName());
String newTableName = metaData.getMetaDataName(newName);
Chat2DBContext.getDbManager().copyTable(
Chat2DBContext.getConnection(),View on GitHub (pinned to 5ee1e990e7)
Solutions
- Check the logged cause for the DB error; remove/disable FK references or use DELETE if TRUNCATE is blocked by constraints.
- Grant TRUNCATE privilege and confirm the table is a base table in the right schema.
- Add an i18n key (e.g. 'ddl.truncateFailed=Failed to truncate table: {0}') and switch the code so the DB message reaches the user.
Example fix
// before
throw new BusinessException("truncate table error", new Object[]{e.getMessage()}, e);
// renders: "truncate table error : no message."
// after (add i18n key)
// ddl.truncateFailed=Failed to truncate table: {0}
throw new BusinessException("ddl.truncateFailed", new Object[]{e.getMessage()}, e); Defensive patterns
Strategy: try-catch
Try / catch
try {
tableService.truncateTable(param);
} catch (BusinessException e) { // code "truncate table error"
// e.getCause() is the DB exception; FK constraints often block TRUNCATE
} Prevention
- Resolve FK references before truncating (or use DELETE).
- Confirm TRUNCATE privilege and base-table status.
- Switch the code to a dotted i18n key to show the DB message.
When it happens
Trigger: The DB rejects TRUNCATE: the table is referenced by foreign keys (TRUNCATE is often blocked by FK constraints), insufficient privileges, table not found, or metadata-name resolution returned an invalid identifier.
Common situations: Truncating a parent table with child FK references; a non-owner user lacking TRUNCATE privilege; case/schema mismatch; an object that is a view, not a base table.
Related errors
- drop table error
- database.delete.prepareFailed
- database.delete.connectionTargetsDeletedDatabase
- database.delete.executeFailed
- database.delete.connectionDatabaseMismatch
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/164197a40ec301b9.
Report an issue: GitHub.