@Bean public HibernateJpaVendorAdapter jpaVendorAdapter() { HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setShowSql(true); jpaVendorAdapter.setGenerateDdl(true); jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.H2Dialect"); return jpaVendorAdapter; }
private HibernateJpaVendorAdapter hibernateJpaVendorAdapter() { HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); hibernateJpaVendorAdapter.setDatabase(Database.POSTGRESQL); hibernateJpaVendorAdapter.setShowSql(true); hibernateJpaVendorAdapter.setGenerateDdl(true); hibernateJpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.PostgreSQL9Dialect"); return hibernateJpaVendorAdapter; }
/** * @return * @throws DataServiceException * @throws EncryptionException */ @Bean(name = "rgbycchEmf") public LocalContainerEntityManagerFactoryBean configureEntityManagerFactory() { LOG.debug("creating instance of LocalContainerEntityManagerFactoryBean (emf)"); LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setPackagesToScan("com.gffny.rgbycch.model"); LOG.debug("creating instance of HibernateJpaVendorAdapter with dialect {}", dialect); HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter(); hibernateJpaVendorAdapter.setDatabasePlatform(dialect); entityManagerFactoryBean.setJpaVendorAdapter(hibernateJpaVendorAdapter); entityManagerFactoryBean.setPersistenceUnitName("rgbycchPU"); Map<String, Object> jpaProperties = entityManagerFactoryBean.getJpaPropertyMap(); jpaProperties.put(org.hibernate.cfg.Environment.DIALECT, dialect); jpaProperties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, hbm2ddlAuto); jpaProperties.put(org.hibernate.cfg.Environment.SHOW_SQL, showSql); jpaProperties.put(org.hibernate.cfg.Environment.FORMAT_SQL, formatSql); jpaProperties.put(org.hibernate.cfg.Environment.ENABLE_LAZY_LOAD_NO_TRANS, true); // enable ordered and batches inserts and updates to improve performance // see // http://vladmihalcea.com/2015/03/18/how-to-batch-insert-and-update-statements-with-hibernate/ jpaProperties.put(org.hibernate.cfg.Environment.ORDER_INSERTS, true); jpaProperties.put(org.hibernate.cfg.Environment.ORDER_UPDATES, true); jpaProperties.put( org.hibernate.cfg.Environment.STATEMENT_BATCH_SIZE, Dialect.DEFAULT_BATCH_SIZE); jpaProperties.put(org.hibernate.cfg.Environment.BATCH_VERSIONED_DATA, true); // 'hibernate.temp.use_jdbc_metadata_defaults' is a temporary magic // value. The need for it is intended to be alleviated with future // development, thus it is not defined as an Environment constant... // // it is used to control whether we should consult the JDBC metadata to // determine certain Settings default values; it is useful to *not* do // this when // the database may not be available (mainly in tools usage). jpaProperties.put("hibernate.temp.use_jdbc_metadata_defaults", "false"); LOG.debug("returning instance of entity manager factory bean"); return entityManagerFactoryBean; }