Example usage for org.hibernate MultiTenancyStrategy DISCRIMINATOR

List of usage examples for org.hibernate MultiTenancyStrategy DISCRIMINATOR

Introduction

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

Prototype

MultiTenancyStrategy DISCRIMINATOR

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

Click Source Link

Document

Multi-tenancy implemented by use of discriminator columns.

Usage

From source file:org.ameba.samples.tenancy.TenancySampleApplication.java

License:Apache License

public @Bean EntityManagerFactory customEntityManagerFactory(DataSource dataSource) {
    HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    vendorAdapter.setGenerateDdl(false); // turn off with Discriminator strategy so far!
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setJpaVendorAdapter(vendorAdapter);
    factory.setPackagesToScan(TenancySampleApplication.class.getPackage().getName());
    factory.setDataSource(dataSource);//from w w w  .  ja  v  a2 s.  c  o m
    factory.getJpaPropertyMap().put(Environment.DIALECT, PostgreSQL9Dialect.class.getName());
    factory.getJpaPropertyMap().put(Environment.MULTI_TENANT, MultiTenancyStrategy.DISCRIMINATOR);
    factory.getJpaPropertyMap().put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, new TenantHolder());
    factory.afterPropertiesSet();
    return factory.getObject();
}