List of usage examples for org.hibernate.cfg AvailableSettings HBM2DDL_AUTO
String HBM2DDL_AUTO
To view the source code for org.hibernate.cfg AvailableSettings HBM2DDL_AUTO.
Click Source Link
From source file:ar.edu.utn.sigmaproject.web.ApplicationConfig.java
License:Open Source License
Properties additionalProperties() { Properties properties = new Properties(); properties.setProperty(AvailableSettings.HBM2DDL_AUTO, this.hbm2ddl); properties.setProperty(AvailableSettings.DIALECT, "org.hibernate.dialect.MySQL5InnoDBDialect"); properties.setProperty(AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true"); return properties; }
From source file:com.corundumstudio.core.extensions.hibernate.BaseTest.java
License:Apache License
protected static void initHibernate() { Properties props = buildDatabaseConfiguration("db1"); Configuration cfg = new Configuration(); cfg.setProperty(Environment.GENERATE_STATISTICS, "true"); cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "create"); cfg.setProperty(AvailableSettings.CACHE_REGION_FACTORY, InfinispanRegionFactory.class.getName()); cfg.setProperty(InfinispanRegionFactory.INFINISPAN_CONFIG_RESOURCE_PROP, "infinispan.xml"); cfg.setProperty(AvailableSettings.QUERY_CACHE_FACTORY, DynamicQueryCacheFactory.class.getName()); cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true"); cfg.setProperty(Environment.USE_QUERY_CACHE, "true"); cfg.addAnnotatedClass(SimpleEntity.class); cfg.buildMappings();/* www .ja v a2 s . c o m*/ ServiceRegistryBuilder sb = new ServiceRegistryBuilder(); ServiceRegistry serviceRegistry = sb.applySettings(props).buildServiceRegistry(); sessionFactory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry); EventListenerRegistry registry = sessionFactory.getServiceRegistry() .getService(EventListenerRegistry.class); registry.getEventListenerGroup(EventType.POST_UPDATE).appendListener(queryCacheEntityListener); registry.getEventListenerGroup(EventType.POST_INSERT).appendListener(queryCacheEntityListener); registry.getEventListenerGroup(EventType.POST_DELETE).appendListener(queryCacheEntityListener); }
From source file:com.github.javarch.persistence.orm.hibernate.conf.HibernatePropertiesConfig.java
License:Apache License
/** * Retorna um objeto Properties com todas as configuraes de propriedades que devem * ser passadas ao {@link SessionFactory}. As propriedades so definidas no arquivo * hibernate.properties que deve estar presente no raiz do classpath. * //from w w w. j av a 2 s . c o m * @return Properties do Hibernate. */ @Bean public Properties hibernateProperties() { Properties props = new Properties(); props.put(AvailableSettings.DIALECT, env.getRequiredProperty(AvailableSettings.DIALECT)); if (env.acceptsProfiles(Profiles.TEST)) { props.put(AvailableSettings.HBM2DDL_AUTO, env.getProperty(AvailableSettings.HBM2DDL_AUTO, "update")); } if (env.acceptsProfiles(Profiles.MULT_TENANT)) { if (log.isDebugEnabled()) { log.debug("Profile Multi Tenancy ativado! Realizando configurao..."); } if (currentIdentifierResolver == null || env.acceptsProfiles(Profiles.PRODUCTION)) { throw new DatabaseConfigurationException( "No foi encontrado nenhum objeto CurrentIdentifierResolver."); } props.put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentIdentifierResolver); props.put(AvailableSettings.DATASOURCE, env.getRequiredProperty(AvailableSettings.DATASOURCE)); props.put(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, multiTenantConnectionProvider); props.put(AvailableSettings.MULTI_TENANT, env.getRequiredProperty(AvailableSettings.MULTI_TENANT)); } else { props.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, true); props.put(AvailableSettings.USE_QUERY_CACHE, true); props.put(AvailableSettings.CACHE_REGION_FACTORY, "org.hibernate.cache.ehcache.EhCacheRegionFactory"); } if (env.acceptsProfiles(Profiles.ENVERS)) { props.put("org.hibernate.envers.versionsTableSuffix", "_audit"); props.put("org.hibernate.envers.revisionFieldName", "revision"); props.put("org.hibernate.envers.default_schema", "audit"); } return props; }
From source file:com.vmware.photon.controller.apife.db.HibernateTestModule.java
License:Open Source License
@Provides @Singleton// w ww. ja v a 2 s . c o m public SessionFactory getSessionFactory() { Configuration configuration = new Configuration(); Reflections reflections = new Reflections("com.vmware.photon.controller.apife.entities"); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class); Reflections baseReflections = new Reflections("com.vmware.photon.controller.apife.entities.base"); classes.addAll(baseReflections.getTypesAnnotatedWith(Entity.class)); Reflections commonReflections = new Reflections("com.vmware.photon.controller.api.common"); classes.addAll(commonReflections.getTypesAnnotatedWith(Entity.class)); for (final Class<?> clazz : classes) { configuration.addAnnotatedClass(clazz); } configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "managed"); configuration.setProperty(AvailableSettings.DIALECT, CustomH2Dialect.class.getName()); configuration.setProperty(AvailableSettings.DRIVER, "org.h2.Driver"); // in memory DB, wait up to 10 seconds after last connection closed before deleting data configuration.setProperty(AvailableSettings.URL, "jdbc:h2:mem:test;DB_CLOSE_DELAY=10"); configuration.setProperty(AvailableSettings.HBM2DDL_AUTO, "create"); configuration.setProperty(AvailableSettings.SHOW_SQL, "true"); configuration.setNamingStrategy(ImprovedNamingStrategy.INSTANCE); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()) .build(); return configuration.buildSessionFactory(serviceRegistry); }
From source file:com.vmware.photon.controller.apife.db.MigrationTest.java
License:Open Source License
@Test public void testMigrations() throws SQLException, LiquibaseException { try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:migrations", "sa", "")) { Liquibase liquibase = new Liquibase("migrations.xml", new ClassLoaderResourceAccessor(), new JdbcConnection(connection)); liquibase.update(""); Configuration configuration = new Configuration(); Reflections reflections = new Reflections("com.vmware.photon.controller.apife.entities"); Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Entity.class); Reflections commonReflections = new Reflections("com.vmware.photon.controller.api.common"); classes.addAll(commonReflections.getTypesAnnotatedWith(Entity.class)); for (final Class<?> clazz : classes) { configuration.addAnnotatedClass(clazz); }/*ww w. j a v a 2s. c o m*/ configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "thread"); configuration.setProperty(AvailableSettings.DIALECT, "org.hibernate.dialect.H2Dialect"); configuration.setProperty(AvailableSettings.DRIVER, "org.h2.Driver"); configuration.setProperty(AvailableSettings.URL, "jdbc:h2:mem:migrations"); configuration.setProperty(AvailableSettings.USER, "sa"); configuration.setProperty(AvailableSettings.PASS, ""); configuration.setProperty(AvailableSettings.HBM2DDL_AUTO, "validate"); configuration.setNamingStrategy(ImprovedNamingStrategy.INSTANCE); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); SessionFactory factory = configuration.buildSessionFactory(serviceRegistry); factory.close(); } }
From source file:de.kaiserpfalzEdv.infopir.backend.db.PersistenceConfiguration.java
License:Apache License
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); entityManagerFactoryBean//from ww w .j a v a2 s. com .setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN)); Properties hibProperties = hibProperties(); entityManagerFactoryBean.setJpaProperties(hibProperties); LOG.debug("Packages to scan: {}", env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN)); LOG.debug("Data Source: {}", dataSource()); LOG.debug("Persistent Provider: {}", HibernatePersistenceProvider.class.getCanonicalName()); LOG.trace("HBM2DDL Auto Setting: {}", hibProperties.getProperty(AvailableSettings.HBM2DDL_AUTO)); LOG.trace("Hibernate Dialect: {}", hibProperties.getProperty(AvailableSettings.DIALECT)); LOG.trace("Show SQL: {}", hibProperties.get(AvailableSettings.SHOW_SQL)); return entityManagerFactoryBean; }
From source file:de.kaiserpfalzEdv.infopir.backend.db.PersistenceConfiguration.java
License:Apache License
private Properties hibProperties() { Properties properties = new Properties(); properties.put(AvailableSettings.HBM2DDL_AUTO, env.getRequiredProperty(AvailableSettings.HBM2DDL_AUTO)); properties.put(AvailableSettings.DIALECT, env.getRequiredProperty(AvailableSettings.DIALECT)); properties.put(AvailableSettings.SHOW_SQL, env.getRequiredProperty(AvailableSettings.SHOW_SQL)); return properties; }
From source file:de.kaiserpfalzEdv.piracc.backend.db.PersistenceConfiguration.java
License:Apache License
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean(); entityManagerFactoryBean.setDataSource(dataSource()); entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class); String[] packages = env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN).split(","); entityManagerFactoryBean.setPackagesToScan(packages); Properties hibProperties = hibProperties(); entityManagerFactoryBean.setJpaProperties(hibProperties); LOG.debug("Packages to scan: {}", env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN)); LOG.debug("Data Source: {}", dataSource()); LOG.debug("Persistent Provider: {}", HibernatePersistenceProvider.class.getCanonicalName()); LOG.trace("HBM2DDL Auto Setting: {}", hibProperties.getProperty(AvailableSettings.HBM2DDL_AUTO)); LOG.trace("Hibernate Dialect: {}", hibProperties.getProperty(AvailableSettings.DIALECT)); LOG.trace("Show SQL: {}", hibProperties.get(AvailableSettings.SHOW_SQL)); return entityManagerFactoryBean; }
From source file:debop4k.data.orm.spring.boot.autoconfigure.HibernateProperties.java
License:Apache License
@SneakyThrows({ IOException.class }) public Properties toProperties() { Properties props = new Properties(); props.put(AvailableSettings.DIALECT, dialect); props.put(AvailableSettings.HBM2DDL_AUTO, hbm2ddl); props.put(AvailableSettings.SHOW_SQL, showSql); props.put(AvailableSettings.FORMAT_SQL, formatSql); props.put(AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, batchFetchSize); if (Stringx.isNotEmpty(isolation)) { props.put(AvailableSettings.ISOLATION, isolation); }//w ww . jav a2 s . c o m props.put(AvailableSettings.AUTOCOMMIT, autoCommit); props.put(AvailableSettings.RELEASE_CONNECTIONS, releaseMode); props.put(AvailableSettings.USE_SECOND_LEVEL_CACHE, useSecondCache); props.put(AvailableSettings.CACHE_PROVIDER_CONFIG, cacheProviderConfig.getFile().getAbsolutePath()); return props; }
From source file:name.livitski.tools.persista.StorageBootstrap.java
License:Open Source License
@SuppressWarnings("unchecked") private void updateSchema() throws ApplicationBeanException { try {/*from ww w. j a v a2 s .com*/ String user = readSetting(UpdaterUserNameSetting.class); String password; if (null != user) password = readSetting(UpdaterPasswordSetting.class); else { user = readSetting(UserNameSetting.class); password = readSetting(PasswordSetting.class); } org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration(); cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "update"); cfg.setProperty(AvailableSettings.DIALECT, readSetting(HibernateSQLDialectSetting.class).getName()); cfg.setProperty(AvailableSettings.DRIVER, getJDBCDriverClass().getName()); cfg.setProperty(AvailableSettings.URL, db.getMetaData().getURL()); cfg.setProperty(AvailableSettings.USER, user); cfg.setProperty(AvailableSettings.PASS, password); for (Class<?> clazz : getEntityClasses()) cfg.addAnnotatedClass(clazz); SchemaUpdate worker = new SchemaUpdate(cfg); worker.setDelimiter(";"); worker.setHaltOnError(true); if (null != ddlDumpFile) worker.setOutputFile(ddlDumpFile.getAbsolutePath()); worker.execute(true, true); List<Throwable> errs = (List<Throwable>) worker.getExceptions(); if (null != errs && !errs.isEmpty()) for (Iterator<Throwable> erri = errs.iterator();;) { Throwable err = erri.next(); if (erri.hasNext()) log().error("", err); else throw new SchemaUpdateException(this, "Error(s) occured during the schema update, the last error is shown.", err); } } catch (ConfigurationException badConfig) { throw new StorageConfigurationException(this, badConfig); } catch (SQLException e) { throw new DatabaseException(this, e); } }