{"record":{"id":"f4d36f3ce8d74775","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-initialize-table","errorCode":null,"errorMessage":"Failed to initialize table","messagePattern":"Failed to initialize table","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java","lineNumber":787,"sourceCode":"                        + \"namespace TEXT, \" + \"key_name VARCHAR(500), \" + \"value_json TEXT, \"\n                        + \"created_at TIMESTAMP, \" + \"updated_at TIMESTAMP\" + \")\";\n                case POSTGRESQL -> \"CREATE TABLE IF NOT EXISTS \" + tableName + \" (\"\n                        + \"pk_id BIGSERIAL PRIMARY KEY, \"\n                        + \"id TEXT NOT NULL, \"\n                        + \"id_hash CHAR(64) NOT NULL UNIQUE, \"\n                        + \"namespace TEXT, \" + \"key_name VARCHAR(500), \" + \"value_json TEXT, \"\n                        + \"created_at TIMESTAMP, \" + \"updated_at TIMESTAMP\" + \")\";\n                case H2 -> \"CREATE TABLE IF NOT EXISTS \" + tableName + \" (\"\n                        + \"pk_id BIGINT AUTO_INCREMENT PRIMARY KEY, \"\n                        + \"id TEXT NOT NULL, \"\n                        + \"id_hash CHAR(64) NOT NULL UNIQUE, \"\n                        + \"namespace TEXT, \" + \"key_name VARCHAR(500), \" + \"value_json TEXT, \"\n                        + \"created_at TIMESTAMP, \" + \"updated_at TIMESTAMP\" + \")\";\n                case OTHER -> throw new UnsupportedOperationException(\n                        \"Unsupported database dialect: \" + dialect + \". Supported dialects: H2, MySQL, PostgreSQL, Oracle\");\n            };\n        } catch (SQLException e) {\n            throw new RuntimeException(\"Failed to initialize table\", e);\n        }\n\n        if (!shouldCreate) {\n            return;\n        }\n\n        try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {\n            stmt.executeUpdate(sql);\n        } catch (SQLException e) {\n            throw new RuntimeException(\"Failed to initialize table\", e);\n        }\n    }\n\n    /**\n     * Check whether a table already exists in the current database schema/catalog.\n     *\n     * @param conn      JDBC connection\n     * @param tableName target table name","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java#L769-L805","documentation":"This is the catch-all branch of initializeTable(): SQLExceptions thrown while building the dialect-specific CREATE TABLE statement (during statement construction / metadata access inside the switch) are wrapped in this RuntimeException. It means table initialization failed before or during DDL preparation.","triggerScenarios":"Constructing DatabaseStore when the dialect switch path throws SQLException (e.g., connection failure while preparing DDL, metadata access problems).","commonSituations":"Database unreachable at first use; driver-specific errors during statement preparation; connection pool exhausted at startup.","solutions":["Check the chained SQLException cause for the underlying database error.","Verify the DataSource connectivity and pool configuration at startup.","Ensure the JDBC driver version matches the database server version.","Retry initialization after restoring connectivity, or fail application startup with a clear message."],"exampleFix":"// before\nDatabaseStore store = new DatabaseStore(dataSource, ...); // throws at startup\n// after\ntry {\n    DatabaseStore store = new DatabaseStore(dataSource, ...);\n} catch (RuntimeException e) {\n    logger.error(\"Table init failed: {}\", e.getCause(), e);\n    throw e; // fail fast with logged cause\n}","handlingStrategy":"try-catch","validationCode":"try (Connection c = dataSource.getConnection()) {\n    if (!c.isValid(2)) throw new IllegalStateException(\"DataSource connection invalid at startup\");\n}","typeGuard":null,"tryCatchPattern":"try { DatabaseStore s = new DatabaseStore(ds, ...); } catch (RuntimeException e) { log.error(\"init failed: {}\", e.getCause(), e); throw new IllegalStateException(\"Store init failed\", e); }","preventionTips":["Validate the DataSource/pool at application startup","Keep pool sizing above concurrent store usage","Test store initialization in CI against the real DB type","Log the chained SQLException cause, not just the wrapper"],"tags":["database","ddl","sql-exception","initialization"],"backgroundTag":"database-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}