休眠多租户(模式)-无法自动创建表

时间:2018-12-27 12:34:56

标签: hibernate

我使用最新的Spring / JPA / Hibernate访问我的MySQL数据库。

配置如下:

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

对于常规(例如单租户)配置,会自动创建缺失表。但是,当我切换到多租户时:

@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;
}

在尝试获取商品时出现以下错误:

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

由于某些原因,在现有的“ tenant_1”架构下不会自动创建丢失的“ Users”表。多租户配置中是否支持表自动创建?还是我错过了什么?

0 个答案:

没有答案