{"record":{"id":"e6c8490a91af75a1","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-delete-item-from-database","errorCode":null,"errorMessage":"Failed to delete item from database","messagePattern":"Failed to delete item 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":623,"sourceCode":"    }\n\n    @Override\n    public boolean deleteItem(List<String> namespace, String key) {\n        validateDeleteItem(namespace, key);\n\n        lock.writeLock().lock();\n        try {\n            String itemId = createItemId(namespace, key);\n            String itemHash = createItemHash(itemId);\n            String sql = \"DELETE FROM \" + tableName + \" WHERE id_hash = ?\";\n\n            try (Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) {\n\n                stmt.setString(1, itemHash);\n                return stmt.executeUpdate() > 0;\n            }\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to delete item from database\", e);\n        } finally {\n            lock.writeLock().unlock();\n        }\n    }\n\n    @Override\n    public StoreSearchResult searchItems(StoreSearchRequest searchRequest) {\n        validateSearchItems(searchRequest);\n\n        lock.readLock().lock();\n        try {\n            List<StoreItem> allItems = getAllItems();\n\n            // Apply filters\n            List<StoreItem> filteredItems = allItems.stream()\n                    .filter(item -> matchesSearchCriteria(item, searchRequest))\n                    .collect(Collectors.toList());\n","sourceCodeStart":605,"sourceCodeEnd":641,"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#L605-L641","documentation":"deleteItem wraps its DELETE execution in a try block; any failure (connection error, SQL error, permissions) is rethrown as RuntimeException(\"Failed to delete item from database\", e) with the original exception as cause, releasing the write lock in finally.","triggerScenarios":"Calling deleteItem when the database is unreachable, the DELETE statement fails due to missing table, foreign-key restrictions, insufficient privileges, or a lock timeout.","commonSituations":"Read-only DB user attempting deletes; DB connection dropped mid-operation; table missing because initialization was skipped in that environment.","solutions":["Inspect e.getCause() for the underlying SQL error","Grant DELETE privileges to the configured DB user","Ensure the store schema/table exists and connectivity is healthy before retrying"],"exampleFix":"// before\nstore.deleteItem(ns, key);\n// after\ntry {\n    store.deleteItem(ns, key);\n} catch (RuntimeException e) {\n    log.error(\"delete failed\", e.getCause());\n}","handlingStrategy":"try-catch","validationCode":"try (Connection c = dataSource.getConnection()) { /* verify connectivity and DELETE grant */ }","typeGuard":null,"tryCatchPattern":"try { boolean removed = store.deleteItem(ns, key); } catch (RuntimeException e) { log.error(\"deleteItem failed: {}\", e.getCause()); }","preventionTips":["Use a DB account with DELETE privileges, not read-only","Ensure table initialization ran in every environment","Retry transient connection failures with backoff","Inspect e.getCause() before blanket-retrying"],"tags":["database","jdbc","delete-failure"],"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"}