alibaba/spring-ai-alibaba · error · RuntimeException
Failed to delete item from database
Error message
Failed to delete item from database
What it means
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.
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
Example fix
// before
store.deleteItem(ns, key);
// after
try {
store.deleteItem(ns, key);
} catch (RuntimeException e) {
log.error("delete failed", e.getCause());
} Defensive patterns
Strategy: try-catch
Validate before calling
try (Connection c = dataSource.getConnection()) { /* verify connectivity and DELETE grant */ } Try / catch
try { boolean removed = store.deleteItem(ns, key); } catch (RuntimeException e) { log.error("deleteItem failed: {}", e.getCause()); } Prevention
- 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
When it happens
Trigger: Calling deleteItem when the database is unreachable, the DELETE statement fails due to missing table, foreign-key restrictions, insufficient privileges, or a lock timeout.
Common situations: Read-only DB user attempting deletes; DB connection dropped mid-operation; table missing because initialization was skipped in that environment.
Related errors
- Failed to clear database store
- Failed to get store size from database
- Failed to retrieve all items from database
- Failed to retrieve item from database
- Failed to store item in database
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/e6c8490a91af75a1.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/store/stores/DatabaseStore.java:623
}
@Override
public boolean deleteItem(List<String> namespace, String key) {
validateDeleteItem(namespace, key);
lock.writeLock().lock();
try {
String itemId = createItemId(namespace, key);
String itemHash = createItemHash(itemId);
String sql = "DELETE FROM " + tableName + " WHERE id_hash = ?";
try (Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, itemHash);
return stmt.executeUpdate() > 0;
}
} catch (Exception e) {
throw new RuntimeException("Failed to delete item from database", e);
} finally {
lock.writeLock().unlock();
}
}
@Override
public StoreSearchResult searchItems(StoreSearchRequest searchRequest) {
validateSearchItems(searchRequest);
lock.readLock().lock();
try {
List<StoreItem> allItems = getAllItems();
// Apply filters
List<StoreItem> filteredItems = allItems.stream()
.filter(item -> matchesSearchCriteria(item, searchRequest))
.collect(Collectors.toList());
View on GitHub (pinned to f82da0b50f)