List of usage examples for org.hibernate MultiTenancyStrategy DATABASE
MultiTenancyStrategy DATABASE
To view the source code for org.hibernate MultiTenancyStrategy DATABASE.
Click Source Link
From source file:com.wms.multitenant.config.TenantDatabaseConfig.java
@Bean(name = "tenantEntityManager") public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, MultiTenantConnectionProvider connectionProvider, CurrentTenantIdentifierResolver tenantResolver) { LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean(); emfBean.setDataSource(dataSource);//from ww w . j a v a 2s . c o m emfBean.setPackagesToScan("com.wms.multitenant.model.tenant"); emfBean.setJpaVendorAdapter(jpaVendorAdapter()); Map<String, Object> properties = new HashMap<>(); properties.put(org.hibernate.cfg.Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE); properties.put(org.hibernate.cfg.Environment.MULTI_TENANT_CONNECTION_PROVIDER, connectionProvider); properties.put(org.hibernate.cfg.Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, tenantResolver); properties.put("hibernate.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy"); properties.put("hibernate.dialect", springEnvironment.getProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")); properties.put("hibernate.show_sql", springEnvironment.getProperty("hibernate.show_sql", "true")); properties.put("hibernate.format_sql", springEnvironment.getProperty("hibernate.format_sql", "true")); properties.put("hibernate.hbm2ddl.auto", springEnvironment.getProperty("hibernate.hbm2ddl.auto", "update")); emfBean.setJpaPropertyMap(properties); return emfBean; }
From source file:eu.supersede.fe.multitenant.MultiTenancyJpaConfiguration.java
License:Apache License
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) { if (dataSource == null) { return null; }/* ww w . j a v a 2 s. c om*/ Map<String, Object> hibernateProps = new LinkedHashMap<>(); hibernateProps.putAll(jpaProperties.getHibernateProperties(dataSource)); hibernateProps.put(Environment.MULTI_TENANT, MultiTenancyStrategy.DATABASE); hibernateProps.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider); hibernateProps.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver); hibernateProps.put(Environment.DIALECT, "org.hibernate.dialect.PostgreSQLDialect"); String HBM2DDL_AUTO = env.getProperty(HBM2DDL_AUTO_PROPERTY); if (HBM2DDL_AUTO != null) { hibernateProps.put(Environment.HBM2DDL_AUTO, HBM2DDL_AUTO); } Set<String> packages = new HashSet<>(); String[] tmp = MODELS_PACKAGES.split(","); for (String t : tmp) { packages.add(t.trim()); } packages.add("eu.supersede.fe.notification.model"); return builder.dataSource(dataSource).packages(packages.toArray(new String[packages.size()])) .properties(hibernateProps).jta(false).build(); }