use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project tutorials by eugenp.
the class UserConfig method userEntityManager.
//
@Primary
@Bean
public LocalContainerEntityManagerFactoryBean userEntityManager() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(userDataSource());
em.setPackagesToScan(new String[] { "org.baeldung.persistence.multiple.model.user" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
final HashMap<String, Object> properties = new HashMap<String, Object>();
properties.put("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
properties.put("hibernate.dialect", env.getProperty("hibernate.dialect"));
em.setJpaPropertyMap(properties);
return em;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project tutorials by eugenp.
the class H2TestProfileJPAConfig method entityManagerFactory.
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.domain", "org.baeldung.boot.domain", "org.baeldung.boot.boottest", "org.baeldung.model" });
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setJpaProperties(additionalProperties());
return em;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project tutorials by eugenp.
the class PersistenceConfig method entityManagerFactory.
// beans
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
em.setJpaProperties(additionalProperties());
return em;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project main by JohnPeng739.
the class DalHibernateConfig method entityManagerFactoryBean.
/**
* 创建实体管理器工厂Bean
*
* @return 实体管理器工厂Bean
*/
@Bean
@DependsOn({ "dataSource" })
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
String database = env.getProperty("jpa.database", String.class, "H2");
String databasePlatform = env.getProperty("jpa.databasePlatform", String.class, "org.hibernate.dialect.H2Dialect");
boolean generateDDL = env.getProperty("jpa.generateDDL", Boolean.class, true);
boolean showSQL = env.getProperty("jpa.showSQL", Boolean.class, true);
HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
adapter.setDatabase(Database.valueOf(database));
adapter.setDatabasePlatform(databasePlatform);
adapter.setGenerateDdl(generateDDL);
adapter.setShowSql(showSQL);
adapter.setPrepareConnection(true);
String[] jpaDefines = context.getBeanNamesForType(JpaEntityPackagesDefine.class);
Set<String> jpaEntityPackages = new HashSet<>();
for (String jpaDefine : jpaDefines) {
JpaEntityPackagesDefine define = context.getBean(jpaDefine, JpaEntityPackagesDefine.class);
jpaEntityPackages.addAll(define.getPackages());
}
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(context.getBean("dataSource", DataSource.class));
emf.setPackagesToScan(jpaEntityPackages.toArray(new String[0]));
emf.setJpaVendorAdapter(adapter);
return emf;
}
use of org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in project flytecnologia-api by jullierme.
the class FlyHibernateConfig method entityManagerFactory.
/**
* @Bean
* public DataSource dataSource() {
* HikariConfig config = new HikariConfig();
* config.setDriverClassName(driver);
* config.setJdbcUrl(url);
* config.setUsername(username);
* config.setPassword(password);
* config.addDataSourceProperty("cachePrepStmts", "true");
* config.addDataSourceProperty("prepStmtCacheSize", "250");
* config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
* config.addDataSourceProperty("useServerPrepStmts", "true");
*
* return new HikariDataSource(config);
* }
*/
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, MultiTenantConnectionProvider multiTenantConnectionProvider, CurrentTenantIdentifierResolver currentTenantIdentifierResolver) {
Properties properties = new Properties();
properties.putAll(jpaProperties.getProperties());
properties.put("spring.jpa.properties.org.hibernate.listeners.envers.autoRegister", false);
properties.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
properties.put(Environment.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider);
properties.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver);
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource);
em.setPackagesToScan("com.flytecnologia", "br.com");
em.setJpaVendorAdapter(jpaVendorAdapter());
em.setJpaProperties(properties);
return em;
}
Aggregations