Spring WebMVC 4.3.3.Release + Spring Data 1.10.3 Release + Hibernate 5.2.2 Final + MySQL 5.7 - Multi-Tenancy Issue
<p>I am trying to resolve a problem related to multi-tenancy of the SpringWebMVC application that is being developed.</p>

<p>Need to create a schema on the fly for every customer who signs up. Once they sign in, all the transactions that they do should be against that schema.</p>

<p>For this I tried to leverage the Hibernate 5 Multi-Tenancy. It works fine - till generating the schema per customer. The application starts with the common schema definition, creates all the entity tables there for the common schema as mentioned in <code>@Table</code> and then before populating the tables (using entity definitions for that schema) tries to insert the data to the <code>schema.table</code> and throws the error that the <code>schema.table</code> is not available.</p>

<p>I am using the class that extends <code>AbstractDataSourceBasedMultiTenantConnectionProviderImpl</code> to provide the <code>Environment.MULTI_TENANT_CONNECTION_PROVIDER</code> through object reference by <code>@Autowired</code> injection. The <code>CurrentTenantIdentifierResolver</code> interface is implemented by a class to provide the object reference to <code>Environment.MULTI_TENANT_IDENTIFIER_RESOLVER</code> through <code>@Autowired</code> injection.</p>

<p>Not sure why Hibernate / JPA provider is not able to populate the tables for the schema which is getting created on the fly. The JPAProperties are as below:</p>

<pre><code>Properties jpaProperties = new Properties();
jpaProperties.put("javax.persistence.schema-generation.database.action", "create-drop");
jpaProperties.put("javax.persistence.create-database-schemas", true);
jpaProperties.put(Environment.HBM2DDL_AUTO, "create-drop");
jpaProperties.put(Environment.DEFAULT_SCHEMA, "base_schema");
jpaProperties.put(Environment.MULTI_TENANT, "SCHEMA");
jpaProperties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, applicationCurrentTenantIdentifierResolver);
jpaProperties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, applicationMultiTenantConnectionProvider);
jpaProperties.put(Environment.FORMAT_SQL, true);
jpaProperties.put("spring.jpa.hibernate.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
jpaProperties.put(Environment.USE_SQL_COMMENTS, true);
jpaProperties.put(Environment.GENERATE_STATISTICS, true);
jpaProperties.put("hbm2dll.create_namespaces", true);
</code></pre>

<p>And the <code>HibernateVendorAdapter</code> has the following values:</p>

<pre><code>HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQL5InnoDBDialect");
vendorAdapter.setShowSql(true);
vendorAdapter.setGenerateDdl(true);
vendorAdapter.setDatabase(Database.MYSQL);
</code></pre>

<p>The POM has the following libraries:</p>

<p>Properties: </p>

<pre><code>&lt;properties&gt;
  &lt;project.mysql.connector.version&gt;5.1.30&lt;/project.mysql.connector.version&gt;
  &lt;project.hibernate.version&gt;5.2.2.Final&lt;/project.hibernate.version&gt;
  &lt;project.spring.orm.version&gt;4.3.3.RELEASE&lt;/project.spring.orm.version&gt;
  &lt;project.spring.data.jpa.version&gt;1.10.3.RELEASE&lt;/project.spring.data.jpa.version&gt;
&lt;/properties&gt;
</code></pre>

<p>And dependencies:</p>

<pre><code>&lt;dependency&gt;
   &lt;groupId&gt;mysql&lt;/groupId&gt;
   &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
   &lt;version&gt;${project.mysql.connector.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
   &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
   &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
   &lt;version&gt;${project.hibernate.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
   &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
   &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
   &lt;version&gt;${project.spring.data.jpa.version}&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
   &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
   &lt;version&gt;${project.spring.orm.version}&lt;/version&gt;
&lt;/dependency&gt;
</code></pre>