Search in sources :

Example 16 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : HashMap(java.util.HashMap) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 17 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 18 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 19 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) HashSet(java.util.HashSet) DataSource(javax.sql.DataSource) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 20 with LocalContainerEntityManagerFactoryBean

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;
}
Also used : Properties(java.util.Properties) JpaProperties(org.springframework.boot.autoconfigure.orm.jpa.JpaProperties) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)75 Bean (org.springframework.context.annotation.Bean)63 HibernateJpaVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)42 Properties (java.util.Properties)14 JpaVendorAdapter (org.springframework.orm.jpa.JpaVendorAdapter)7 HashMap (java.util.HashMap)4 JpaConfigDataHolder (org.apereo.cas.configuration.model.support.jpa.JpaConfigDataHolder)4 Test (org.junit.jupiter.api.Test)4 DependsOn (org.springframework.context.annotation.DependsOn)4 Lazy (org.springframework.context.annotation.Lazy)4 AbstractJpaProperties (org.apereo.cas.configuration.model.support.jpa.AbstractJpaProperties)2 DatabaseProperties (org.apereo.cas.configuration.model.support.jpa.DatabaseProperties)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Primary (org.springframework.context.annotation.Primary)2 DefaultPersistenceUnitManager (org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager)2 DatabaseManager (com.fredboat.backend.quarterdeck.db.DatabaseManager)1 AugmentableQueryRepositoryFactoryBean (com.thinkbiganalytics.metadata.jpa.feed.AugmentableQueryRepositoryFactoryBean)1 DataSourceBean (de.alpharogroup.springconfig.DataSourceBean)1 JdbcUrlBean (de.alpharogroup.springconfig.JdbcUrlBean)1 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)1