Skip to content

Clear cached prepared statements when switching JDBC connections - #167

Open
foc-nico wants to merge 5 commits into
ebean-orm:mainfrom
FOCONIS:clear-prepared-statement-cache
Open

foc-nico wants to merge 5 commits into
ebean-orm:mainfrom
FOCONIS:clear-prepared-statement-cache

Conversation

@foc-nico

@foc-nico foc-nico commented Nov 20, 2026 •

Copy link
Copy Markdown

Motivation

When a pooled connection switches to a different tenant’s JDBC connection, a cached prepared statement can still execute against the previous connection and return data from the wrong tenant.

This PR exposes clearPreparedStatementCache() through the new DataSourceConnection interface. The new pool listener overloads receive the pool and a DataSourceConnection, allowing the borrow listener to close and evict cached statements after switching connections and before the next query. Prepared statements remain cached between switches.

Verification

The H2 regression test runs the same query on the same pooled connection before and after switching between two tenant databases. With cache clearing enabled, the query returns 20 from the second tenant. With cache clearing disabled, it returns 10 from the first tenant and the test fails.

@foc-nico
foc-nico marked this pull request as ready for review November 20, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant