Example usage for org.hibernate MultiTenancyStrategy SCHEMA

List of usage examples for org.hibernate MultiTenancyStrategy SCHEMA

Introduction

In this page you can find the example usage for org.hibernate MultiTenancyStrategy SCHEMA.

Prototype

MultiTenancyStrategy SCHEMA

To view the source code for org.hibernate MultiTenancyStrategy SCHEMA.

Click Source Link

Document

Multi-tenancy implemented as separate schemas.

Usage

From source file:br.com.uktech.multitenantschema.config.PersistenceMultiTenantConfig.java

License:Open Source License

@Bean("multiTenantEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean multiTenantEntityManagerFactory(DataSource dataSource,
        MultiTenantConnectionProvider multiTenantConnectionProvider,
        CurrentTenantIdentifierResolver tenantIdentifierResolver) {

    LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
    emfBean.setDataSource(dataSource);//from   w  ww  . j av  a2s . c o m
    emfBean.setPackagesToScan(getMultiTenantPackagesToScan());
    emfBean.setJpaVendorAdapter(jpaVendorAdapter());

    Map<String, Object> jpaProperties = new HashMap<>();

    jpaProperties.put(org.hibernate.cfg.Environment.SHOW_SQL, "true");
    jpaProperties.put(org.hibernate.cfg.Environment.FORMAT_SQL, "true");
    jpaProperties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, "update");

    jpaProperties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    jpaProperties.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER,
            multiTenantConnectionProvider);
    jpaProperties.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantIdentifierResolver);
    emfBean.setJpaPropertyMap(jpaProperties);

    return emfBean;
}

From source file:com.billkoch.examples.hibernate.config.HibernateConfig.java

License:Apache License

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    Map<String, Object> properties = new HashMap<>();
    properties.putAll(jpaProperties.getHibernateProperties(tenantsDataSource()));

    properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
    properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, connectionProvider());
    properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver());

    return builder.dataSource(tenantsDataSource()).packages("com.billkoch.examples").properties(properties)
            .build();//from   w  ww.  j a v a 2  s  .c o m
}