{"record":{"id":"bf3a9029b7e4de0e","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-clear-database-store","errorCode":null,"errorMessage":"Failed to clear database store","messagePattern":"Failed to clear database store","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":720,"sourceCode":"            if (offset >= namespaces.size()) {\n                return Collections.emptyList();\n            }\n\n            int endIndex = Math.min(offset + limit, namespaces.size());\n            return namespaces.subList(offset, endIndex);\n        } finally {\n            lock.readLock().unlock();\n        }\n    }\n\n    @Override\n    public void clear() {\n        String sql = \"DELETE FROM \" + tableName;\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 clear database store\", e);\n        }\n    }\n\n    @Override\n    public long size() {\n        String sql = \"SELECT COUNT(*) FROM \" + tableName;\n\n        try (Connection conn = dataSource.getConnection();\n             Statement stmt = conn.createStatement();\n             ResultSet rs = stmt.executeQuery(sql)) {\n\n            rs.next();\n            return rs.getLong(1);\n        } catch (SQLException e) {\n            throw new RuntimeException(\"Failed to get store size from database\", e);\n        }\n    }\n","sourceCodeStart":702,"sourceCodeEnd":738,"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#L702-L738","documentation":"DatabaseStore.clear() executes a DELETE FROM on the store's table and wraps any SQLException in this RuntimeException. It means the full-table delete could not be executed against the configured DataSource. The original SQLException is chained as the cause.","triggerScenarios":"Calling store.clear() when the database is unreachable, the table was dropped manually, the connection credentials are wrong, or the user lacks DELETE privilege on the table.","commonSituations":"Database restarted or network dropped mid-session; table deleted by a migration; read-only DB user; wrong JDBC URL pointing at a schema without the store table.","solutions":["Check the chained SQLException cause to see the real database error (connection refused, unknown table, access denied).","Verify connectivity with the same DataSource from a simple test query (SELECT 1).","Confirm the store table still exists and the DB user has DELETE privilege.","If the table is gone, re-create it by re-instantiating DatabaseStore or calling its initialization path."],"exampleFix":"// before\nstore.clear();\n// after\ntry {\n    store.clear();\n} catch (RuntimeException e) {\n    logger.error(\"Store clear failed; cause: {}\", e.getCause(), e);\n    // reconnect / re-init store before retrying\n}","handlingStrategy":"try-catch","validationCode":"// before clear\ntry (Connection c = dataSource.getConnection(); Statement s = c.createStatement()) {\n    s.executeQuery(\"SELECT 1\");\n} catch (SQLException e) { /* DB unreachable - fix before clear */ }","typeGuard":null,"tryCatchPattern":"try { store.clear(); } catch (RuntimeException e) { Throwable root = e.getCause(); log.error(\"clear failed: {}\", root, e); }","preventionTips":["Verify DB connectivity at application startup","Grant DELETE privilege to the app DB user","Never drop the store table externally","Wrap store maintenance ops in retry with backoff"],"tags":["database","jdbc","sql-exception","store"],"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"}