MultiTenant Hibernate + Spring boot - How to prevent it from looking up for a connection during server startup

We are using multi tenant hibernate + Spring boot (2.2.0) as described in Multi-Tenancy in Hibernate. We are providing MultiTenantConnectionProvider and CurrentTenantIdentifierResolver when creating the entity manager (Refer to sample below).

In our MultiTenantConnectionProvider, The target database for a tenant is not statically configured. Instead, It dynamically determines the target database details of current tenant by calling another service and then creates datasource for it.

Now , we are facing an issue that when spring boot server is started, Hibernate is making a call to MultiTenantConenctionProvider.getAnyConnection() method. At the time of server startup, there is no tenant in the context and hence we do not have any database to create a connection for. Also, we do not have any dummy database in our setup which we can use during server startup time

  1. If we return null, the server startup fails with a NullPointerException
  2. If we override anyConnection() method and throw an exception (as can be see in the code below), the server just logs the exception and continues with the server startup.

With 2, Things work fine and we are able to make progress. However, we really want to get rid of this unnecessary exception being logged everytime the spring boot server is restarted.

We are looking for a way to turn off hibernate behaviour of trying to connect to a db during server startup especially when hibernate’s multi-tenant strategy is set. This behavior is inconsistent for a multi-tenant software

Is there any way, we can prevent hiberate from trying get a connection (i.e making a call to MultiTenantConenctionProvider.getAnyConnection()) during server startup ?

Please advise

Following is a sample of our Spring configuration

@Configuration
@EnableTransactionManagement
public class MultiTenantHibernateJpaConfig {

    @Autowired
    private JpaProperties jpaProperties;

    @Bean
    public MultiTenantConnectionProvider multiTenantConnectionProvider() {
        return new MultiTenantConnectionProviderImpl();
    }

    @Bean
    public CurrentTenantIdentifierResolver currentTenantIdentifierResolver() {
        return new CurrentTenantIdentifierResolverImpl();
    }

    @Value("${jpaconfig.packages-to-scan:#{null}}")
    private String packagesToScan;

    @Bean
    @Primary
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(MultiTenantConnectionProvider multiTenantConnectionProvider,
                                                                       CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {

        Map<String, Object> hibernateProps = new LinkedHashMap<>();
        hibernateProps.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
        hibernateProps.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
        hibernateProps.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);

        hibernateProps.put("javax.persistence.schema-generation.database.action", "none");
        hibernateProps.put("javax.persistence.query.timeout", "5");
        hibernateProps.put(Environment.DIALECT, "org.hibernate.dialect.Oracle10gDialect");
        hibernateProps.putAll(this.jpaProperties.getProperties());

        LocalContainerEntityManagerFactoryBean result = new LocalContainerEntityManagerFactoryBean();
        if(packagesToScan != null) {
            //handle multiple packages separated by comma
            result.setPackagesToScan(packagesToScan.split("\\s*,\\s*"));
        }
        result.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
        result.setJpaPropertyMap(hibernateProps);

        return result;
    }

Following is the MultiTenantConnectionProvider implementation

public class MultiTenantConnectionProviderImpl extends AbstractDataSourceBasedMultiTenantConnectionProviderImpl {

    private static final long serialVersionUID = 1L;


    public MultiTenantConnectionProviderImpl()
    {
    }

    @Override
    protected DataSource selectAnyDataSource()
    {
        return null;
    }

    @Override
    protected DataSource selectDataSource(String tenantIdentifier) {
        //This in turn makes a call to a remote service to fetch current tenant 
        //database details and then creates a datasource for it.
        return DataSourceManager.getDataSource(tenantIdentifier);
    }

    @Override
    public Connection getAnyConnection() throws SQLException{
        //Called during server startup. Cannot do any thing  as tenant is not known
        // and there is no default datasource
        throw new SQLException("not implemented in multi-tenant environment");
    }

    @Override
    public void releaseAnyConnection(Connection connection) throws SQLException
    {
        //Called during server startup. Cannot do any thing  as tenant is not known
        // and there is no default datasource
        throw new SQLException("not implemented in multi-tenant environment");
    }
}

1 Like

Will appreciate any help on this issue

Hi,
we are facing the same issue.
Any help would appreciated.

br Andreas

Did you check why the connection is acquired? Usually, determining the Dialect or schema validation requires a connection. I think you can set the configuration property hibernate.temp.use_jdbc_metadata_defaults to false and configure a Dialect manually to avoid this. Of course you also have to disable schema validation and hibernate.hbm2ddl.auto to update.

HI beikov,

we came to the same solution. But in spring-boot version 5.2.3 and hibernate -core 5.4.10 this problem didn’t appear. Since we updated to spring-boot version 5.3.1 and hibernate-core 5.4.23 our services throw this NullPointerException on startup. After some investigation we found out that an entitymanager is requested without any tenant-identifier set. But we can’t find out who requested the entitymanager and/or why this is be done on startup.

Maybe this stacktrace is helpfull to get to the root of the problem:

HHH000342: Could not obtain connection to query metadata2021-01-29T16:27:08.393+01:00 java.lang.NullPointerException: null2021-01-29T16:27:08.393+01:00
at org.hibernate.engine.jdbc.connections.spi.AbstractDataSourceBasedMultiTenantConnectionProviderImpl.getAnyConnection(AbstractDataSourceBasedMultiTenantConnectionProviderImpl.java:25) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$MultiTenantConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:207) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.(InFlightMetadataCollectorImpl.java:176) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) ~[hibernate-core-5.4.23.Final.jar!/:5.4.23.Final]2021-01-29T16:27:08.393+01:00
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:409) ~[spring-orm-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1847) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1784) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:233) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1235) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:494) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.orm.jpa.EntityManagerFactoryUtils.findEntityManagerFactory(EntityManagerFactoryUtils.java:121) ~[spring-orm-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.orm.jpa.EntityManagerFactoryAccessor.setBeanFactory(EntityManagerFactoryAccessor.java:155) ~[spring-orm-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1810) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1775) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:609) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1367) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:885) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:789) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.393+01:00
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:539) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1585) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1549) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1438) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1325) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:714) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1415) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:409) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1367) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1287) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:714) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1415) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:608) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:409) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1179) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:571) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:531) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[spring-beans-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:203) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addServletContextInitializerBeans(ServletContextInitializerBeans.java:97) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.ServletContextInitializerBeans.(ServletContextInitializerBeans.java:86) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:259) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:233) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5166) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at java.base/java.util.concurrent.FutureTask.run(Unknown Source) ~[na:na]2021-01-29T16:27:08.394+01:00
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source) ~[na:na]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:843) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at java.base/java.util.concurrent.FutureTask.run(Unknown Source) ~[na:na]2021-01-29T16:27:08.394+01:00
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at java.base/java.util.concurrent.AbstractExecutorService.submit(Unknown Source) ~[na:na]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) ~[tomcat-embed-core-9.0.39.jar!/:9.0.39]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.(TomcatWebServer.java:104) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:451) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:200) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:159) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:582) ~[spring-context-5.3.1.jar!/:5.3.1]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:144) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:767) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:426) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.SpringApplication.run(SpringApplication.java:326) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[spring-boot-2.4.0.jar!/:2.4.0]2021-01-29T16:27:08.394+01:00
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[spring-boot-2.4.0.jar!/:2.4.0]

1 Like

If you look into org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator#initiateService you can see that this connection is only acquired if hibernate.temp.use_jdbc_metadata_defaults is true. Like I wrote before, you must set the value for this property to false.

1 Like

Thank you for such a valuable information. It is very important for me.

Thanks for the replies. It’s great! Software development in our country is a very popular area and many young people want to do it. Some areas still do not look attractive for software developers and this is sad. For example, the tourism software industry. As someone who runs a travel blog, I read some very interesting information here https://bmmagazine.co.uk/business/custom-software-development-for-the-travel-industry/ on how important it is to develop quality software in the travel industry and how important it is to select a quality team for this. From integrating with multiple systems to resolving booking issues, incompatible payment systems, CRMs, vendor systems, and distribution issues, the challenges that travel companies face are not so small or insignificant. These and many problems can be fixed. You agree with me?

Thanks @beikov . Appreciate your response. This helps to resolve the issue.

Additionally, i see that spring boot 2.3.4 version which has dependency on hibernate 5.4.21.Final, the full exception stack trace is no longer logged. Instead , benign warn message is logged.

{"@timestamp":"2021-04-02T17:04:32.841-07:00","@version":"1","message":"HHH000342: Could not obtain connection to query metadata : not implemented in multi-tenant environment","logger_name":"org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator","thread_name":"Test worker","level":"WARN","level_value":30000}

I had same issue, it resolved by applying your suggestion.
Thanks a lot.