@Bean public EntityManagerFactory entityManagerFactory() { logger.debug("Configuring EntityManager"); LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setPersistenceProvider(new HibernatePersistenceProvider()); lcemfb.setPersistenceUnitName("persistenceUnit"); lcemfb.setDataSource(dataSource()); lcemfb.setJpaDialect(new HibernateJpaDialect()); lcemfb.setJpaVendorAdapter(jpaVendorAdapter()); lcemfb.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); Properties jpaProperties = new Properties(); jpaProperties.put("hibernate.generate_statistics", false); jpaProperties.put("hibernate.show_sql", Boolean.parseBoolean(databaseShowSQL)); lcemfb.setJpaProperties(jpaProperties); lcemfb.setPackagesToScan("cn.org.once.cstack.model"); lcemfb.afterPropertiesSet(); return lcemfb.getObject(); }
@Bean public EntityManagerFactory entityManagerFactory() { logger.debug("Configuring EntityManager"); LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setPersistenceProvider(new HibernatePersistenceProvider()); lcemfb.setPersistenceUnitName("persistenceUnit"); lcemfb.setDataSource(dataSource()); lcemfb.setJpaDialect(new HibernateJpaDialect()); lcemfb.setJpaVendorAdapter(jpaVendorAdapter()); lcemfb.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE); Properties jpaProperties = new Properties(); jpaProperties.put("hibernate.generate_statistics", true); jpaProperties.put("hibernate.show_sql", Boolean.parseBoolean(databaseShowSQL)); lcemfb.setJpaProperties(jpaProperties); lcemfb.setPackagesToScan("cn.org.once.cstack.model"); lcemfb.afterPropertiesSet(); return lcemfb.getObject(); }
@Bean(EntityManagerFactoryBeanName) @Primary public LocalContainerEntityManagerFactoryBean entityManagerFactory( @Qualifier(DataSourceBeanName) DataSource dataSource, @Qualifier(JpaVendorAdapterBeanName) JpaVendorAdapter vendorAdapter) { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource); entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter); entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect()); entityManagerFactoryBean.setPackagesToScan(Organization.class.getPackage().getName()); entityManagerFactoryBean.setPersistenceUnitName("mysqlsource1"); entityManagerFactoryBean.afterPropertiesSet(); return entityManagerFactoryBean; }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean(); emf.setJpaDialect(new HibernateJpaDialect()); emf.setJpaVendorAdapter(jpaVendorAdapter()); emf.setJpaPropertyMap(jpaProperties()); emf.setPackagesToScan(Constants.APPLICATION_ROOT_PACKAGE); emf.setDataSource(dataSource); // Setup Papertrail before Liquibase papertrailConfig.configureAuditLogAppender(); // Run Liquibase migrations before ORM setup liquibaseConfig.upgradeDatabase(); return emf; }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws URISyntaxException { LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaDialect(new HibernateJpaDialect()); HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setGenerateDdl(true); factory.setJpaVendorAdapter(vendorAdapter); factory.setPersistenceUnitName("production"); factory.setPackagesToScan("app.domain"); factory.setDataSource(dataSource()); factory.afterPropertiesSet(); return factory; }
@Bean public LocalContainerEntityManagerFactoryBean metaEntityManager(EntityManagerFactoryBuilder builder, @Qualifier("metaDataSource") DataSource dataSource) { Map<String, Object> props = new HashMap<>(); props.putAll(jpaProps.getSubProperties("properties.")); // props.put("hibernate.hbm2ddl.auto", "create"); LocalContainerEntityManagerFactoryBean factory = builder.dataSource(dataSource) .jta(true) .persistenceUnit("metaPU") .packages("de.weichert.multitenancy") .properties(props) .build(); factory.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); factory.setJpaDialect(new HibernateJpaDialect()); return factory; }
@Bean @Nonnull public EntityManagerFactory entityManagerFactory() throws SQLException { final Properties properties = new Properties(); properties.setProperty("hibernate.dialect", env.getProperty("db.hibernate.dialect")); properties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("db.hibernate.hbm2ddl.auto")); properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false"); final LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); factory.setJpaDialect(new HibernateJpaDialect()); factory.setDataSource(pgDataSource()); factory.setPackagesToScan(this.getClass().getPackage().getName()); factory.setJpaProperties(properties); factory.afterPropertiesSet(); return factory.getObject(); }
@Bean(name = "entityManagerFactory") public EntityManagerFactory entityManagerFactory() { LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setDataSource(dataSource()); lcemfb.setJpaDialect(new HibernateJpaDialect()); lcemfb.setJpaVendorAdapter(jpaVendorAdapter()); lcemfb.setPackagesToScan("org.springframework.data.demo"); lcemfb.setPersistenceUnitName("persistenceUnit"); lcemfb.setPersistenceXmlLocation("classpath:META-INF/persistence.xml"); lcemfb.getJpaPropertyMap().put("hibernate.ejb.naming_strategy", org.hibernate.cfg.ImprovedNamingStrategy.class.getCanonicalName()); if ("mysql".equals(databaseType)) { lcemfb.getJpaPropertyMap().put("hibernate.dialect", org.hibernate.dialect.MySQL5InnoDBDialect.class.getCanonicalName()); } else if ("h2".equals(databaseType)) { lcemfb.getJpaPropertyMap().put("hibernate.dialect", org.hibernate.dialect.H2Dialect.class.getCanonicalName()); } else if ("derby".equals(databaseType)) { lcemfb.getJpaPropertyMap().put("hibernate.dialect", org.hibernate.dialect.DerbyTenSevenDialect.class.getCanonicalName()); } else { throw new RuntimeException("database.type must be configured"); } lcemfb.getJpaPropertyMap().put("hibernate.hbm2ddl.auto", "update"); lcemfb.getJpaPropertyMap().put("hibernate.hbm2ddl.format", "false"); lcemfb.getJpaPropertyMap().put("hibernate.hbm2ddl.export", "true"); lcemfb.getJpaPropertyMap().put("cache.provider_class", "org.hibernate.cache.NoCacheProvider"); lcemfb.afterPropertiesSet(); return lcemfb.getObject(); }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws PropertyVetoException, ClassNotFoundException { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); /** * Renamed to jpa-persistence.xml cause Spring will manage the DataSource and not the * container. */ entityManagerFactoryBean.setPersistenceXmlLocation("classpath*:META-INF/jpa-persistence.xml"); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect()); entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); entityManagerFactoryBean.setJpaProperties(getJpaProperties()); return entityManagerFactoryBean; }
public Properties jpaProperties() { Properties props = new Properties(); props.put(Environment.HBM2DDL_AUTO, "create"); // create | spawn | spawn-drop | update | validate | none props.put(Environment.FORMAT_SQL, "true"); props.put(Environment.SHOW_SQL, "true"); props.put(Environment.RELEASE_CONNECTIONS, ConnectionReleaseMode.ON_CLOSE); props.put(Environment.AUTOCOMMIT, "true"); props.put(Environment.STATEMENT_BATCH_SIZE, 100); props.put(Environment.DIALECT, getDialect()); props.put("jpaDialect", HibernateJpaDialect.class.getName()); return props; }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() throws PropertyVetoException { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); /** * Renamed to jpa-persistence.xml cause Spring will manage the DataSource and not the * container. */ entityManagerFactoryBean.setPersistenceXmlLocation("classpath*:META-INF/jpa-persistence.xml"); entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect()); entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); return entityManagerFactoryBean; }
@Bean @DependsOn({"cacheManager", "springLiquibase"}) public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setDatabase(jpaVendorDatabase); final Map<String, Object> jpaProperties = new LinkedHashMap<>(); jpaProperties.put("hibernate.cache.region.factory_class", hibernateEhcacheRegionFactoryClass); jpaProperties.put("hibernate.cache.use_query_cache", hibernateUseQueryCache); jpaProperties.put("hibernate.cache.use_second_level_cache", hibernateUseSecondLevelCache); jpaProperties.put("hibernate.hbm2ddl.auto", hibernateHbm2ddl); final LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect()); entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter); entityManagerFactoryBean.setPackagesToScan("org.unidle.domain"); entityManagerFactoryBean.setJpaPropertyMap(jpaProperties); entityManagerFactoryBean.setMappingResources("jpa/orm.xml"); return entityManagerFactoryBean; }
@Bean(EntityManagerFactoryBeanName) public LocalContainerEntityManagerFactoryBean entityManagerFactory( @Qualifier(DataSourceBeanName) DataSource dataSource, @Qualifier(JpaVendorAdapterBeanName) JpaVendorAdapter vendorAdapter) { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource); entityManagerFactoryBean.setJpaVendorAdapter(vendorAdapter); entityManagerFactoryBean.setJpaDialect(new HibernateJpaDialect()); entityManagerFactoryBean.setPackagesToScan(Organization.class.getPackage().getName()); entityManagerFactoryBean.setPersistenceUnitName("mysqlsource2"); entityManagerFactoryBean.afterPropertiesSet(); return entityManagerFactoryBean; }
@Bean public FactoryBean<EntityManagerFactory> entityManagerFactory() { LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); factory.setDataSource(dataSource()); factory.setJpaVendorAdapter(jpaVendorAdapter()); factory.setPackagesToScan("com.namics.oss.spring.support.i18n.dao.jpa"); factory.setPersistenceUnitName("jpaPersistenceUnit"); factory.setJpaProperties(jpaProperties()); factory.setJpaDialect(new HibernateJpaDialect()); return factory; }
@Bean @Autowired public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { JpaTransactionManager txManager = new JpaTransactionManager(); JpaDialect jpaDialect = new HibernateJpaDialect(); txManager.setEntityManagerFactory(entityManagerFactory); txManager.setJpaDialect(jpaDialect); return txManager; }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); vendorAdapter.setGenerateDdl(Boolean.TRUE); vendorAdapter.setShowSql(Boolean.TRUE); factory.setDataSource(dataSource()); factory.setJpaVendorAdapter(vendorAdapter); factory.setPackagesToScan("com.whenling"); factory.setJpaDialect(new HibernateJpaDialect()); Properties jpaProperties = new Properties(); jpaProperties.put("hibernate.id.new_generator_mappings", false); jpaProperties.put("hibernate.hbm2ddl.auto", hibernateHbm2ddlAuto); jpaProperties.put("hibernate.dialect", hibernateDialect); jpaProperties.put("hibernate.show_sql", hibernateShowSql); jpaProperties.put("hibernate.format_sql", hibernateFormatSql); jpaProperties.put("hibernate.current_session_context_class", hibernateCurrentSessionContextClass); jpaProperties.put("javax.persistence.validation.mode", javaxPersistenceValidationMode); jpaProperties.put("hibernate.query.substitutions", hibernateQuerySubstitutions); jpaProperties.put("hibernate.default_batch_fetch_size", hibernateDefaultBatchFetchSize); jpaProperties.put("hibernate.max_fetch_depth", hibernateMaxFetchDepth); jpaProperties.put("hibernate.enable_lazy_load_no_trans", hibernateEnableLazyLoadNoTrans); jpaProperties.put("hibernate.bytecode.use_reflection_optimizer", hibernateBytecodeUseReflectionOptimizer); jpaProperties.put("hibernate.cache.use_second_level_cache", hibernateCacheUseSecondLevelCache); jpaProperties.put("hibernate.cache.region.factory_class", hibernateCacheInfinispanRegionFactoryClass); // jpaProperties.put("hibernate.cache.infinispan.cfg", hibernateCacheInfinispanCfg); jpaProperties.put("javax.persistence.sharedCache.mode", javaxPersistenceSharedCacheMode); jpaProperties.put("hibernate.generate_statistics", hibernateGenerateStatistics); jpaProperties.put("hibernate.cache.use_query_cache", hibernateCacheUseQueryCache); factory.setJpaProperties(jpaProperties); return factory; }
@Bean @Autowired public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) { JpaDialect jpaDialect = new HibernateJpaDialect(); JpaTransactionManager txManager = new JpaTransactionManager(); txManager.setEntityManagerFactory(entityManagerFactory); txManager.setJpaDialect(jpaDialect); return txManager; }
@Bean public EntityManagerFactory entityManagerFactory() { LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); factoryBean.setDataSource(dataSource()); factoryBean.setJpaDialect(new HibernateJpaDialect()); factoryBean.setJpaVendorAdapter(jpaVendorAdapter()); factoryBean.setPersistenceUnitName("persistenceUnit"); factoryBean.setJpaProperties(jpaProperties()); factoryBean.setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITY_MANAGER_PACKAGES_TO_SCAN)); factoryBean.afterPropertiesSet(); return factoryBean.getObject(); }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactoryRealm() { final LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setDataSource(dataSourceRealm()); lcemfb.setPersistenceXmlLocation("classpath:META-INF/persistence-realm.xml"); lcemfb.setJpaVendorAdapter(jpaVendorAdapterRealm()); lcemfb.setJpaDialect(new HibernateJpaDialect()); return lcemfb; }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactoryWorld() { final LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setDataSource(dataSourceWorld()); lcemfb.setPersistenceXmlLocation("classpath:META-INF/persistence-world.xml"); lcemfb.setJpaVendorAdapter(jpaVendorAdapterWorld()); lcemfb.setJpaDialect(new HibernateJpaDialect()); return lcemfb; }
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); lcemfb.setDataSource(dataSourceAuth()); lcemfb.setJpaVendorAdapter(jpaVendorAdapterAuth()); lcemfb.setJpaDialect(new HibernateJpaDialect()); return lcemfb; }
/** * Initializes the hypersonic db. */ public synchronized void init(String... packagesToScan) { if (ArrayUtils.isEmpty(packagesToScan)) { throw new RuntimeException("Package names to scan must be provided as arg"); } if (isInitialized()) { //If already initialized just return cleanly return; } try { dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setUrl("jdbc:hsqldb:mem:sprite"); dataSource.setUsername("sa"); dataSource.setPassword(""); JpaDialect dialect = new HibernateJpaDialect(); LocalContainerEntityManagerFactoryBean localEMFactory = new LocalContainerEntityManagerFactoryBean(); localEMFactory.setJpaDialect(dialect); localEMFactory.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); localEMFactory.setDataSource(dataSource); localEMFactory.setPackagesToScan(packagesToScan); //localEMFactory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver()); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("eclipselink.logging.level", "FINE"); properties.put("eclipselink.logging.level.sql", "FINE"); properties.put("hibernate.hbm2ddl.auto", "create-drop"); properties.put("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); properties.put("PersistenceVersion", "2.1"); localEMFactory.setJpaPropertyMap(properties); localEMFactory.afterPropertiesSet(); entityManagerFactory = localEMFactory.getObject(); jdbcTemplate = new JdbcTemplate(dataSource); transactionManager = new JpaTransactionManager(); transactionManager.setJpaDialect(dialect); transactionManager.setEntityManagerFactory(entityManagerFactory); transactionManager.setDataSource(dataSource); } catch (Exception ex) { ex.printStackTrace(); fail("Failed to initialize entityManager: " + ex); } initialized = true; }
@Bean public JpaDialect jpaDialect() { return new HibernateJpaDialect(); }
@Bean public HibernateJpaDialect hibernateJpaDialect() { return new HibernateJpaDialect(); }
@Bean public HibernateJpaDialect hibernateJpaDialect(){ return new HibernateJpaDialect(); }