It looks like the default database is optional, but I haven't tested.
You could defer the datasource connection on the first statement with LazyConnectionDataSourceProxy. It is a proxy for your datasource that will lazy initialize underlying JDBC connection (and thus defer everything that depends on it).
This article have a different use case, but they are combining AbstractRoutingDataSource
with LazyConnectionDataSourceProxy
, I believe this is what you are looking for.
The other option is to play with JPA bootstrap mode, but in this case, you will have to wait for each JDBC connection to be resolved in the pool and the EntityManagerFactory to be initialized.