Schema-based multitenancy: getting “java.sql.SQLException: No database selected” from time to time

My code written in Java, and I using Spring JDBC Template for accessing MySQL database. My system is a multi-tenant and each tenant has its own dedicated schema in MySQL (e.g. “tenant_1”, “tenant_2”, etc). This is how database connection being initialized: During bootstrap, I creating a bean exposing DataSourceTransactionManager, which is initialized by DataSource configured…