Last active
August 3, 2017 16:12
-
-
Save jose-mgmaestre/5d9dcab622f167006863e22a95a7c0cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PropertySource("classpath:/com/myco/app.properties") | |
@Configuration | |
public class ApplicationConfig { | |
@Autowired | |
Environment env; | |
//... | |
@Bean | |
public LocalContainerEntityManagerFactoryBean entityManagerFactory(){ | |
//Configure the vendor adapter | |
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); | |
vendorAdapter.setDatabasePlatform(env.getProperty("database.dialect")); | |
//Create the factory bean | |
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); | |
factoryBean.setPersistenceUnitManager(pum()); | |
factoryBean.setJpaVendorAdapter(vendorAdapter); | |
Map<String, Object> multitenancyMap = new HashMap<String, Object>(); | |
multitenancyMap.put("hibernate.multi_tenant_connection_provider", multitenancyConnectionProvider()); | |
multitenancyMap.put("hibernate.tenant_identifier_resolver", tenantResolver()); | |
multitenancyMap.put("hibernate.multiTenancy", "DATABASE"); | |
factoryBean.setJpaPropertyMap(multitenancyMap); | |
} | |
@Bean | |
public MultiTenantConnectionProviderImpl multitenancyConnectionProvider(){ | |
return new MultiTenantConnectionProviderImpl(); | |
} | |
@Bean | |
public CurrentTenantIdentifierResolverImpl tenantResolver(){ | |
return new CurrentTenantIdentifierResolverImpl(); | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is the definition of pum()?