Java Code Examples for org.hibernate.cfg.Configuration#setProperty()

The following examples show how to use org.hibernate.cfg.Configuration#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchedulerDbManagerRecoveryTest.java    From scheduling with GNU Affero General Public License v3.0 6 votes vote down vote up
private SchedulerDBManager createDatabase(boolean wipeOnStartup) throws URISyntaxException {
    String configureFilename = "hibernate-update.cfg.xml";

    if (wipeOnStartup) {
        configureFilename = "hibernate.cfg.xml";
    }

    Configuration config = new Configuration().configure(new File(this.getClass()
                                                                      .getResource("/functionaltests/config/" +
                                                                                   configureFilename)
                                                                      .toURI()));

    if (config.getProperty("hibernate.connection.url").contains(HsqldbServer.HSQLDB)) {
        String jdbcUrl = "jdbc:hsqldb:file:" + dbFolder.getRoot().getAbsolutePath() +
                         ";create=true;hsqldb.tx=mvcc;hsqldb.write_delay=false";

        config.setProperty("hibernate.connection.url", jdbcUrl);
    }

    return new SchedulerDBManager(config, wipeOnStartup);
}
 
Example 2
Source File: BaseCacheProviderTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void configure(Configuration cfg) {
	super.configure( cfg );
	cfg.setProperty( Environment.CACHE_REGION_PREFIX, "" );
	cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
	cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
	cfg.setProperty( Environment.USE_STRUCTURED_CACHE, "true" );
	cfg.setProperty( Environment.CACHE_PROVIDER, getCacheProvider().getName() );

	if ( getConfigResourceKey() != null ) {
		cfg.setProperty( getConfigResourceKey(), getConfigResourceLocation() );
	}

	if ( useTransactionManager() ) {
		cfg.setProperty( Environment.CONNECTION_PROVIDER, DummyConnectionProvider.class.getName() );
		cfg.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY, DummyTransactionManagerLookup.class.getName() );
	}
	else {
		cfg.setProperty( Environment.TRANSACTION_STRATEGY, JDBCTransactionFactory.class.getName() );
	}
}
 
Example 3
Source File: BaseCoreFunctionalTestCase.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected Configuration constructConfiguration() {
  Configuration configuration = new Configuration();
  configuration.setProperty( AvailableSettings.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName() );
  configuration.setProperty( AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
  if ( createSchema() ) {
    configuration.setProperty( Environment.HBM2DDL_AUTO, "update" );
    final String secondSchemaName = createSecondSchema();
    if ( StringHelper.isNotEmpty( secondSchemaName ) ) {
      if ( !( getDialect() instanceof H2Dialect ) ) {
        throw new UnsupportedOperationException( "Only H2 dialect supports creation of second schema." );
      }
      Helper.createH2Schema( secondSchemaName, configuration );
    }
  }
  configuration.setImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
  configuration.setProperty( Environment.DIALECT, getDialect().getClass().getName() );
  return configuration;
}
 
Example 4
Source File: AbstractJPATest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void configure(Configuration cfg) {
	super.configure( cfg );
	cfg.setProperty( Environment.JPAQL_STRICT_COMPLIANCE, "true" );
	cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
	cfg.setEntityNotFoundDelegate( new JPAEntityNotFoundDelegate() );
	cfg.getEventListeners().setPersistEventListeners( buildPersistEventListeners() );
	cfg.getEventListeners().setPersistOnFlushEventListeners( buildPersisOnFlushEventListeners() );
	cfg.getEventListeners().setAutoFlushEventListeners( buildAutoFlushEventListeners() );
	cfg.getEventListeners().setFlushEventListeners( buildFlushEventListeners() );
	cfg.getEventListeners().setFlushEntityEventListeners( buildFlushEntityEventListeners() );
}
 
Example 5
Source File: HibernateSessionManager.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Try to figure out which Hibernate dialect to use.
 *
 * @param conf Actual Hibernate configuration
 */
private static void determineDialect(Configuration conf) {
	String datasourceJndi = conf.getProperty(PROPERTY_DATASOURCE_JNDI);

	if (datasourceJndi == null) {
		throw new IllegalStateException("The property hibernate.connection.datasource is not set in file");
	}

	String figuredOutValue = getDialect(datasourceJndi);
	logger.warn("Property hibernate.dialect set to " + figuredOutValue);
	conf.setProperty(PROPERTY_DIALECT, figuredOutValue);

}
 
Example 6
Source File: CollectionTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(Configuration cfg) {
    super.configure(cfg);
    cfg.setProperty(Environment.DRIVER, org.h2.Driver.class.getName());
    cfg.setProperty(Environment.URL, "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;");
    cfg.setProperty(Environment.USER, "sa");
    cfg.setProperty(Environment.PASS, "");
    cfg.setProperty(Environment.CACHE_REGION_PREFIX, "");
    cfg.setProperty(Environment.GENERATE_STATISTICS, "true");

    cfg.setProperty(Environment.SHOW_SQL, "true");
    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
    cfg.setProperty(Environment.USE_QUERY_CACHE, "true");
    cfg.setProperty(Environment.CACHE_REGION_FACTORY, RedissonRegionFactory.class.getName());
}
 
Example 7
Source File: HibernateExceptionUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenMissingTable_whenSchemaValidated_thenSchemaManagementException() {
    thrown.expect(SchemaManagementException.class);
    thrown.expectMessage("Schema-validation: missing table");

    Configuration cfg = getConfiguration();
    cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "validate");
    cfg.addAnnotatedClass(Product.class);
    cfg.buildSessionFactory();
}
 
Example 8
Source File: HibernateProjectionsIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
private static Configuration getConfiguration() {
    Configuration cfg = new Configuration();
    cfg.setProperty(AvailableSettings.DIALECT,
        "org.hibernate.dialect.H2Dialect");
    cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "none");
    cfg.setProperty(AvailableSettings.DRIVER, "org.h2.Driver");
    cfg.setProperty(AvailableSettings.URL,
        "jdbc:h2:mem:myexceptiondb2;DB_CLOSE_DELAY=-1;;INIT=RUNSCRIPT FROM 'src/test/resources/products.sql'");
    cfg.setProperty(AvailableSettings.USER, "sa");
    cfg.setProperty(AvailableSettings.PASS, "");
    cfg.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "thread");
    return cfg;
}
 
Example 9
Source File: TransactionalTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(Configuration cfg) {
    super.configure(cfg);
    cfg.setProperty(Environment.DRIVER, org.h2.Driver.class.getName());
    cfg.setProperty(Environment.URL, "jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;");
    cfg.setProperty(Environment.USER, "sa");
    cfg.setProperty(Environment.PASS, "");
    cfg.setProperty(Environment.CACHE_REGION_PREFIX, "");
    cfg.setProperty(Environment.GENERATE_STATISTICS, "true");

    cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true");
    cfg.setProperty(Environment.USE_QUERY_CACHE, "true");
    cfg.setProperty(Environment.CACHE_REGION_FACTORY, RedissonRegionFactory.class.getName());
}
 
Example 10
Source File: PropertyRefTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	cfg.setProperty(Environment.DEFAULT_BATCH_FETCH_SIZE, "1");
	cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
 
Example 11
Source File: StatsTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	super.configure( cfg );
	cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
 
Example 12
Source File: KeyManyToOneTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configure(Configuration cfg) {
	super.configure( cfg );
	cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
 
Example 13
Source File: NativeSQLQueriesTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	super.configure( cfg );
	cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
 
Example 14
Source File: SubselectFetchTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
 
Example 15
Source File: ClassicTranslatorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	super.configure( cfg );
	cfg.setProperty( Environment.QUERY_TRANSLATOR, ClassicQueryTranslatorFactory.class.getName() );
}
 
Example 16
Source File: JoinedSubclassOneToOneTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	cfg.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
	cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
 
Example 17
Source File: OptionalOneToOneTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false");
	cfg.setProperty(Environment.GENERATE_STATISTICS, "true");
}
 
Example 18
Source File: ComponentTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void configure(Configuration cfg) {
	cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
}
 
Example 19
Source File: HibernateConfig.java    From kardio with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor to initialize the hibernate configuration
 */
private HibernateConfig(){
	logger.info("** Initializing Hibernate Connection **");
	Configuration configuration = new Configuration();

	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.AlertSubscriptionEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.ComponentEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.ComponentFailureLogEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.ComponentTypeEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.CounterEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.CounterMetricEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.CounterMetricHistoryEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.CounterMetricTypeEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.DaillyCompStatusEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.EnvCounterEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.EnvironmentEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.HealthCheckEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.HealthCheckParamEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.HealthCheckTypeEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.RegionEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.StatusEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.ContainerStatsEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.ApiStatusEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.PromLookupEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.TpsServiceEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.TpsLatHistoryEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.K8sApiStatusEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.K8sTpsLatHistoryEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.K8sObjectPodsEntity.class);
	configuration.addAnnotatedClass(com.tmobile.kardio.surveiller.db.entity.K8sPodsContainersEntity.class);
	
	configuration.setProperty("hibernate.connection.driver_class", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_DRIVER_CLASS) );
    configuration.setProperty("hibernate.connection.url", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_URL) );                                
    configuration.setProperty("hibernate.connection.username", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_USERNAME) );     
    configuration.setProperty("hibernate.connection.password", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_PASSWORD) );
    configuration.setProperty("hibernate.dialect", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_HIBERNATE_DIALECT) );
    configuration.setProperty("hibernate.hbm2ddl.auto", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_HIBERNATE_HBM2DDL) );
    configuration.setProperty("hibernate.show_sql", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_HIBERNATE_SHOWSQL) );
    configuration.setProperty("hibernate.connection.pool_size", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_HIBERNATE_POOLSIZE) );
    configuration.setProperty("hibernate.enhancer.enableLazyInitialization", propertyUtil.getValue(SurveillerConstants.CONFIG_DB_HIBERNATE_LX_INIT) );
    configuration.setProperty("hibernate.current_session_context_class", "org.hibernate.context.internal.ThreadLocalSessionContext");
    
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
	sessionFactory = configuration.buildSessionFactory(builder.build());
	logger.info("** Initializing Hibernate Connection Completed **");
}
 
Example 20
Source File: HiwayDB.java    From Hi-WAY with Apache License 2.0 2 votes vote down vote up
private SessionFactory getSQLSessionMessung() {
	try {

		String url = dbURL.substring(0, dbURL.lastIndexOf("/")) + "/messungen";

		Configuration configuration = new Configuration();

		configuration.setProperty("hibernate.connection.url", url);
		configuration.setProperty("hibernate.connection.username", username);
		if (this.password != null) {
			configuration.setProperty("hibernate.connection.password", this.password);
		} else {
			configuration.setProperty("hibernate.connection.password", "");
		}

		configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");
		configuration.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");

		configuration.setProperty("connection.provider_class", "org.hibernate.connection.C3P0ConnectionProvider");

		configuration.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");

		configuration.setProperty("hibernate.current_session_context_class", "thread");

		configuration.setProperty("hibernate.initialPoolSize", "20");
		configuration.setProperty("hibernate.c3p0.min_size", "5");
		configuration.setProperty("hibernate.c3p0.max_size", "1000");

		configuration.setProperty("hibernate.maxIdleTime", "3600");
		configuration.setProperty("hibernate.c3p0.maxIdleTimeExcessConnections", "300");

		configuration.setProperty("hibernate.c3p0.timeout", "330");
		configuration.setProperty("hibernate.c3p0.idle_test_period", "300");

		configuration.setProperty("hibernate.c3p0.max_statements", "13000");
		configuration.setProperty("hibernate.c3p0.maxStatementsPerConnection", "30");

		configuration.setProperty("hibernate.c3p0.acquire_increment", "10");

		configuration.addAnnotatedClass(de.huberlin.hiwaydb.dal.Accesstime.class);

		StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
		SessionFactory sessionFactory = configuration.buildSessionFactory(builder.build());

		return sessionFactory;

	} catch (Throwable ex) {
		System.err.println("Failed to create sessionFactory object." + ex);
		throw new ExceptionInInitializerError(ex);
	}

}