{"record":{"id":"164197a40ec301b9","repo":"OtterMind/Chat2DB","slug":"truncate-table-error","errorCode":"truncate table error","errorMessage":"truncate table error","messagePattern":"truncate table error","errorType":"exception","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbTableServiceImpl.java","lineNumber":312,"sourceCode":"            DefaultSQLExecutor.getInstance().execute(connection, sql, resultSet -> null);\n        } catch (Exception e) {\n            log.error(\"drop table error\", e);\n            throw new BusinessException(\"drop table error\", new Object[]{e.getMessage()}, e);\n        }\n    }\n\n    @Override\n    public void truncateTable(DbTableQueryRequest param) {\n        try {\n            IDbMetaData metaData = Chat2DBContext.getDbMetaData();\n            Connection connection = Chat2DBContext.getConnection();\n            String name = metaData.getMetaDataName(param.getTableName());\n            String sql = Chat2DBContext.getDbManager()\n                    .truncateTable(connection, param.getDatabaseName(), param.getSchemaName(), name);\n            DefaultSQLExecutor.getInstance().execute(connection, sql, resultSet -> null);\n        } catch (Exception e) {\n            log.error(\"truncate table error\", e);\n            throw new BusinessException(\"truncate table error\", new Object[]{e.getMessage()}, e);\n        }\n    }\n\n    @Override\n    public void copyTable(DbTableCopyRequest param) {\n        try {\n            IDbMetaData metaData = Chat2DBContext.getDbMetaData();\n            String newName = param.getNewName();\n            if (StringUtils.isBlank(newName)) {\n                newName = param.getTableName() + \"_copy_\" + DateUtil.format(new Date(), \"MMddHHmmss\");\n                if (newName.length() > 32) {\n                    newName = newName.substring(0, 32);\n                }\n            }\n            String tableName = metaData.getMetaDataName(param.getTableName());\n            String newTableName = metaData.getMetaDataName(newName);\n            Chat2DBContext.getDbManager().copyTable(\n                    Chat2DBContext.getConnection(),","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/db/DbTableServiceImpl.java#L294-L330","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nthrow new BusinessException(\"truncate table error\", new Object[]{e.getMessage()}, e);\n// renders: \"truncate table error : no message.\"\n\n// after (add i18n key)\n// ddl.truncateFailed=Failed to truncate table: {0}\nthrow new BusinessException(\"ddl.truncateFailed\", new Object[]{e.getMessage()}, e);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    tableService.truncateTable(param);\n} catch (BusinessException e) { // code \"truncate table error\"\n    // e.getCause() is the DB exception; FK constraints often block TRUNCATE\n}","preventionTips":["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."],"tags":["ddl","table-operations","i18n-missing-key","database-error"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}