alibaba/spring-ai-alibaba · error · RuntimeException
Failed to clear database store
Error message
Failed to clear database store
What it means
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.
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.
Example fix
// before
store.clear();
// after
try {
store.clear();
} catch (RuntimeException e) {
logger.error("Store clear failed; cause: {}", e.getCause(), e);
// reconnect / re-init store before retrying
} Defensive patterns
Strategy: try-catch
Validate before calling
// before clear
try (Connection c = dataSource.getConnection(); Statement s = c.createStatement()) {
s.executeQuery("SELECT 1");
} catch (SQLException e) { /* DB unreachable - fix before clear */ } Try / catch
try { store.clear(); } catch (RuntimeException e) { Throwable root = e.getCause(); log.error("clear failed: {}", root, e); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to get store size from database
- Failed to retrieve all items from database
- Failed to delete item from database
- Failed to delete item from MongoDB-like storage
- Failed to initialize table
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/bf3a9029b7e4de0e.
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:720
if (offset >= namespaces.size()) {
return Collections.emptyList();
}
int endIndex = Math.min(offset + limit, namespaces.size());
return namespaces.subList(offset, endIndex);
} finally {
lock.readLock().unlock();
}
}
@Override
public void clear() {
String sql = "DELETE FROM " + tableName;
try (Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement()) {
stmt.executeUpdate(sql);
} catch (SQLException e) {
throw new RuntimeException("Failed to clear database store", e);
}
}
@Override
public long size() {
String sql = "SELECT COUNT(*) FROM " + tableName;
try (Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
rs.next();
return rs.getLong(1);
} catch (SQLException e) {
throw new RuntimeException("Failed to get store size from database", e);
}
}
View on GitHub (pinned to f82da0b50f)