{"record":{"id":"544d1b63a707378a","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-retrieve-all-items-from-database","errorCode":null,"errorMessage":"Failed to retrieve all items from database","messagePattern":"Failed to retrieve all items from database","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":875,"sourceCode":"     * @return list of all items\n     */\n    private List<StoreItem> getAllItems() {\n        List<StoreItem> items = new ArrayList<>();\n        String sql = \"SELECT namespace, key_name, value_json, created_at, updated_at FROM \" + tableName;\n\n        try (Connection conn = dataSource.getConnection();\n             Statement stmt = conn.createStatement();\n             ResultSet rs = stmt.executeQuery(sql)) {\n\n            while (rs.next()) {\n                try {\n                    items.add(resultSetToStoreItem(rs));\n                } catch (Exception e) {\n                    // Skip invalid items\n                }\n            }\n        } catch (SQLException e) {\n            throw new RuntimeException(\"Failed to retrieve all items from database\", e);\n        }\n\n        return items;\n    }\n\n    /**\n     * Convert ResultSet to StoreItem.\n     *\n     * @param rs result set\n     * @return StoreItem\n     * @throws Exception if conversion fails\n     */\n    @SuppressWarnings(\"unchecked\")\n    private StoreItem resultSetToStoreItem(ResultSet rs) {\n        try {\n            String namespaceJson = rs.getString(\"namespace\");\n            String key = rs.getString(\"key_name\");\n            String valueJson = rs.getString(\"value_json\");","sourceCodeStart":857,"sourceCodeEnd":893,"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#L857-L893","documentation":"DatabaseStore's all-items retrieval (SELECT of every row) wraps SQLExceptions from the query execution in this RuntimeException. Individual rows that fail to deserialize are silently skipped; only a whole-query SQL failure raises this error.","triggerScenarios":"Listing all store items when the database is unreachable, the table was dropped, or the query fails due to permissions or corruption.","commonSituations":"Admin/debug listing against a DB that went down; table removed by external tooling; schema drift after manual DDL changes.","solutions":["Check the chained SQLException cause for the root database error.","Verify the table exists and the user has SELECT privilege.","Restore connectivity / reconnect the DataSource and retry.","Avoid dropping/rename of the store table outside library-managed initialization."],"exampleFix":"// before\nList<StoreItem> all = store.listAllItems(); // no handling\n// after\ntry {\n    List<StoreItem> all = store.listAllItems();\n} catch (RuntimeException e) {\n    logger.error(\"list failed: {}\", e.getCause(), e);\n}","handlingStrategy":"retry","validationCode":"try (Connection c = dataSource.getConnection()) {\n    c.createStatement().executeQuery(\"SELECT 1 FROM \" + tableName + \" WHERE 1=0\");\n}","typeGuard":null,"tryCatchPattern":"try { List<StoreItem> all = store.listAll(); } catch (RuntimeException e) { log.error(\"list failed: {}\", e.getCause(), e); /* retry after reconnect */ }","preventionTips":["Protect the store table from external drops/renames","Grant SELECT privilege to the app user","Add connection-retry logic around bulk reads","Watch DB error logs during bulk listing operations"],"tags":["database","jdbc","select-query","store"],"backgroundTag":"sql-query-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"}