Maybe InheritableThreadLocal + DataSourceProxy could do this? There is java Tenant DataSource Proxy implementation: https://github.com/callistaenterprise/blog-multitenancy/blob/shared_database_postgres_rls/multi-tenant-service/src/main/java/se/callista/blog/service/multitenancy/datasource/TenantAwareDataSource.java