Hibernate multi-tenancy (schema) - cannot auto create tables

Viewed 335

I using latest Spring/JPA/Hibernate for accessing my MySQL database.

Configuration is as the following:

spring.jpa.hibernate.ddl-auto=create
spring.datasource.username=root
spring.datasource.password=

With regular (e.g. single tenant) configuration missing tables are created automatically. However, when I switching to multi-tenant:

@Bean
public LocalContainerEntityManagerFactoryBean 
entityManagerFactory(DataSource dataSource,

MultiTenantConnectionProvider multiTenantConnectionProviderImpl,

    CurrentTenantIdentifierResolver currentTenantIdentifierResolverImpl) {
    Map<String, Object> properties = new HashMap<>();
    properties.putAll(jpaProperties.getProperties());
    properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, 
    multiTenantConnectionProviderImpl);
    properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, 
    currentTenantIdentifierResolverImpl);
    LocalContainerEntityManagerFactoryBean em = new 
    LocalContainerEntityManagerFactoryBean();
    em.setDataSource(dataSource);
    em.setPackagesToScan("com.xxx");
    em.setJpaVendorAdapter(jpaVendorAdapter());
    em.setJpaPropertyMap(properties);
    return em;
}

I getting the following error while trying to get items:

java.sql.SQLSyntaxErrorException: Table 'tenant_1.User' doesn't exist

For some reason, missing "Users" table is not automatically created under existing "tenant_1" schema. Does table auto-creation supported in multi-tenant configuration? Or I missing something?

0 Answers
Related