org.hibernate.boot.registry.StandardServiceRegistryBuilder Java Examples

The following examples show how to use org.hibernate.boot.registry.StandardServiceRegistryBuilder. 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: HibernateUtil.java    From tutorials with MIT License 6 votes vote down vote up
public static SessionFactory getSessionFactory() {
    try {
        Properties properties = getProperties();
        Configuration configuration = new Configuration();
        configuration.setProperties(properties);
        configuration.addAnnotatedClass(Person.class);
        configuration.addAnnotatedClass(Address.class);
        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        return sessionFactory;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sessionFactory;
}
 
Example #2
Source File: HibernateUtil.java    From robe with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static SessionFactory buildSessionFactory(Class<?> testClass){
    Configuration configuration = new Configuration();
    configuration.setProperty("connection.driver_class","org.h2.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + testClass.getSimpleName());
    configuration.setProperty("hibernate.connection.username", "sa");
    configuration.setProperty("hibernate.connection.password", "");
    configuration.setProperty("dialect", "org.hibernate.dialect.H2Dialect");
    configuration.setProperty("hibernate.hbm2ddl.auto", "update");
    configuration.setProperty("show_sql", "true");
    configuration.setProperty(" hibernate.connection.pool_size", "10");

    Reflections reflections = new Reflections("io.robe.hibernate.test.entity");

    Set<Class<?>> classes = reflections.getTypesAnnotatedWith(javax.persistence.Entity.class);

    for(Class<?> clazz : classes) {
        configuration.addAnnotatedClass(clazz);
    }

    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example #3
Source File: SpannerServiceContributor.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
  serviceRegistryBuilder
      // The custom Hibernate schema management tool for Spanner.
      .addInitiator(new StandardServiceInitiator() {
        @Override
        public Service initiateService(Map configurationValues,
            ServiceRegistryImplementor registry) {
          return SCHEMA_MANAGEMENT_TOOL;
        }

        @Override
        public Class getServiceInitiated() {
          return SchemaManagementTool.class;
        }
      })
      // The user agent JDBC connection property to identify the library.
      .applySetting("hibernate.connection.userAgent", HIBERNATE_API_CLIENT_LIB_TOKEN)
      // Create a unique index for a table if it does not already exist when in UPDATE mode.
      .applySetting(
          "hibernate.schema_update.unique_constraint_strategy",
          UniqueConstraintSchemaUpdateStrategy.RECREATE_QUIETLY)
      // Allows entities to be used with InheritanceType.JOINED in Spanner.
      .applySetting("hibernate.hql.bulk_id_strategy", InlineIdsOrClauseBulkIdStrategy.INSTANCE);
}
 
Example #4
Source File: SpannerTableExporterTests.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Set up the metadata for Hibernate to generate schema statements.
 */
@Before
public void setup() throws SQLException {
  JDBCMockObjectFactory jdbcMockObjectFactory = new JDBCMockObjectFactory();
  jdbcMockObjectFactory.registerMockDriver();

  this.connection = jdbcMockObjectFactory.getMockConnection();
  this.connection.setMetaData(MockJdbcUtils.metaDataBuilder().build());
  jdbcMockObjectFactory.getMockDriver().setupConnection(this.connection);

  this.registry = new StandardServiceRegistryBuilder()
      .applySetting("hibernate.dialect", SpannerDialect.class.getName())
      .applySetting("hibernate.connection.url", "unused")
      .build();

  this.metadata =
      new MetadataSources(this.registry).addAnnotatedClass(TestEntity.class).buildMetadata();
}
 
Example #5
Source File: HibernateUtil.java    From journaldev with MIT License 6 votes vote down vote up
private static SessionFactory buildSessionAnnotationFactory() {
   	try {
           // Create the SessionFactory from hibernate.cfg.xml
       	Configuration configuration = new Configuration();
       	configuration.configure("hibernate-annotation.cfg.xml");
       	System.out.println("Hibernate Annotation Configuration loaded");
       	
       	ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
       	System.out.println("Hibernate Annotation serviceRegistry created");
       	
       	SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
       	
           return sessionFactory;
       }
       catch (Throwable ex) {
           // Make sure you log the exception, as it might be swallowed
           System.err.println("Initial SessionFactory creation failed." + ex);
           throw new ExceptionInInitializerError(ex);
       }
}
 
Example #6
Source File: HibernateUtil.java    From journaldev with MIT License 6 votes vote down vote up
private static SessionFactory buildSessionFactory() {
	try {
		// Create the SessionFactory from hibernate.cfg.xml
		Configuration configuration = new Configuration();
		configuration.configure("hibernate.cfg.xml");
		System.out.println("Hibernate Configuration loaded");

		ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
				.applySettings(configuration.getProperties()).build();
		System.out.println("Hibernate serviceRegistry created");

		SessionFactory sessionFactory = configuration
				.buildSessionFactory(serviceRegistry);

		return sessionFactory;
	} catch (Throwable ex) {
		System.err.println("Initial SessionFactory creation failed." + ex);
		ex.printStackTrace();
		throw new ExceptionInInitializerError(ex);
	}
}
 
Example #7
Source File: PersistJSONUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Before
public void init() {
    try {
        Configuration configuration = new Configuration();

        Properties properties = new Properties();
        properties.load(Thread.currentThread()
            .getContextClassLoader()
            .getResourceAsStream("hibernate-persistjson.properties"));

        configuration.setProperties(properties);

        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
            .build();
        MetadataSources metadataSources = new MetadataSources(serviceRegistry);
        metadataSources.addAnnotatedClass(Customer.class);

        SessionFactory factory = metadataSources.buildMetadata()
            .buildSessionFactory();

        session = factory.openSession();
    } catch (HibernateException | IOException e) {
        fail("Failed to initiate Hibernate Session [Exception:" + e.toString() + "]");
    }
}
 
Example #8
Source File: HibernateDatabase.java    From livingdoc-confluence with GNU General Public License v3.0 6 votes vote down vote up
public HibernateDatabase(Properties properties) throws HibernateException {

        StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(properties).build();
        MetadataSources metadataSources = new MetadataSources(registry);
        metadataSources.addAnnotatedClass(SystemInfo.class)
            .addAnnotatedClass(Project.class)
            .addAnnotatedClass(Runner.class)
            .addAnnotatedClass(Repository.class)
            .addAnnotatedClass(RepositoryType.class)
            .addAnnotatedClass(SystemUnderTest.class)
            .addAnnotatedClass(Requirement.class)
            .addAnnotatedClass(Specification.class)
            .addAnnotatedClass(Reference.class)
            .addAnnotatedClass(Execution.class);

        this.properties = properties;
        this.metadata = metadataSources.buildMetadata();

    }
 
Example #9
Source File: HibernateUtil.java    From tutorials with MIT License 6 votes vote down vote up
private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate-annotation.cfg.xml
        Configuration configuration = new Configuration();
        configuration.addAnnotatedClass(Employee.class);
        configuration.addAnnotatedClass(Project.class);
        configuration.configure("manytomany.cfg.xml");
        System.out.println("Hibernate Annotation Configuration loaded");

        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
            .build();
        System.out.println("Hibernate Annotation serviceRegistry created");

        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);

        return sessionFactory;
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
}
 
Example #10
Source File: HibernateLoggingIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Before
public void setUp() throws IOException {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure("hibernate-logging.cfg.xml")
        .build();
    try {
        sessionFactory = new MetadataSources(registry).buildMetadata()
            .buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();
        session.save(new Employee("John Smith", "001"));
        session.getTransaction()
            .commit();
        session.close();
    } catch (Exception e) {
        fail(e);
        StandardServiceRegistryBuilder.destroy(registry);
    }
}
 
Example #11
Source File: TeiidServer.java    From teiid-spring-boot with Apache License 2.0 6 votes vote down vote up
private Metadata getMetadata(Set<BeanDefinition> components, PhysicalNamingStrategy namingStrategy,
        MetadataFactory mf) {
    ServiceRegistry registry = metadataSources.getServiceRegistry();
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(
            (BootstrapServiceRegistry) registry).applySetting(AvailableSettings.DIALECT, TeiidDialect.class)
            .build();
    // Generate Hibernate model based on @Entity definitions
    for (BeanDefinition c : components) {
        try {
            Class<?> clazz = Class.forName(c.getBeanClassName());
            metadataSources.addAnnotatedClass(clazz);
        } catch (ClassNotFoundException e) {
        }
    }
    return metadataSources.getMetadataBuilder(serviceRegistry).applyPhysicalNamingStrategy(namingStrategy).build();
}
 
Example #12
Source File: WikiHibernateUtil.java    From dkpro-jwpl with Apache License 2.0 6 votes vote down vote up
public static SessionFactory getSessionFactory(DatabaseConfiguration config) {

        if (config.getLanguage() == null) {
            throw new ExceptionInInitializerError("Database configuration error. 'Language' is empty.");
        }
        else if (config.getHost() == null) {
            throw new ExceptionInInitializerError("Database configuration error. 'Host' is empty.");
        }
        else if (config.getDatabase() == null) {
            throw new ExceptionInInitializerError("Database configuration error. 'Database' is empty.");
        }

        String uniqueSessionKey = config.getLanguage().toString() + config.getHost() + config.getDatabase();
        if (!sessionFactoryMap.containsKey(uniqueSessionKey)) {
        	Configuration configuration = getConfiguration(config);
            StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
            SessionFactory sessionFactory = configuration.buildSessionFactory(ssrb.build());
            sessionFactoryMap.put(uniqueSessionKey, sessionFactory);
        }
        return sessionFactoryMap.get(uniqueSessionKey);
    }
 
Example #13
Source File: HibernateUtil.java    From collect-earth with MIT License 6 votes vote down vote up
private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
    	Configuration configuration = new Configuration();
    	configuration.configure("hibernate.cfg.xml");
    	System.out.println("Hibernate Configuration loaded");
    	
    	configuration.addAnnotatedClass(Plot.class); 
    	
    	ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    	System.out.println("Hibernate serviceRegistry created");
    	
    	SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
 
        return sessionFactory;
    }
    catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        ex.printStackTrace();
        throw new ExceptionInInitializerError(ex);
    }
}
 
Example #14
Source File: SchemaUpdate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static StandardServiceRegistry buildStandardServiceRegistry(CommandLineArgs parsedArgs) throws Exception {
	final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().build();
	final StandardServiceRegistryBuilder ssrBuilder = new StandardServiceRegistryBuilder( bsr );

	if ( parsedArgs.cfgXmlFile != null ) {
		ssrBuilder.configure( parsedArgs.cfgXmlFile );
	}

	if ( parsedArgs.propertiesFile != null ) {
		Properties props = new Properties();
		props.load( new FileInputStream( parsedArgs.propertiesFile ) );
		ssrBuilder.applySettings( props );
	}

	return ssrBuilder.build();
}
 
Example #15
Source File: BootstrapAPIIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void whenServiceRegistryAndMetadata_thenSessionFactory() throws IOException {

    BootstrapServiceRegistry bootstrapRegistry = new BootstrapServiceRegistryBuilder()
            .build();

    ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder(bootstrapRegistry)
            // No need for hibernate.cfg.xml file, an hibernate.properties is sufficient.
            //.configure()
            .build();

    MetadataSources metadataSources = new MetadataSources(standardRegistry);
    metadataSources.addAnnotatedClass(Movie.class);

    Metadata metadata = metadataSources.getMetadataBuilder().build();

    sessionFactory = metadata.buildSessionFactory();
    assertNotNull(sessionFactory);
    sessionFactory.close();
}
 
Example #16
Source File: EntityManagerFactoryBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void processConfigXml(
		LoadedConfig loadedConfig,
		MergedSettings mergedSettings,
		StandardServiceRegistryBuilder ssrBuilder) {
	if ( ! mergedSettings.configurationValues.containsKey( SESSION_FACTORY_NAME ) ) {
		// there is not already a SF-name in the merged settings
		final String sfName = loadedConfig.getSessionFactoryName();
		if ( sfName != null ) {
			// but the cfg.xml file we are processing named one..
			mergedSettings.configurationValues.put( SESSION_FACTORY_NAME, sfName );
		}
	}

	mergedSettings.configurationValues.putAll( loadedConfig.getConfigurationValues() );
	ssrBuilder.configure( loadedConfig );
}
 
Example #17
Source File: EntityManagerFactoryBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void configure(StandardServiceRegistryBuilder ssrBuilder) {

		applyJdbcConnectionProperties( ssrBuilder );
		applyTransactionProperties( ssrBuilder );

		// flush before completion validation
		if ( "true".equals( configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) {
			ssrBuilder.applySetting( Environment.FLUSH_BEFORE_COMPLETION, "false" );
			LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION );
		}

//		final StrategySelector strategySelector = ssrBuilder.getBootstrapServiceRegistry().getService( StrategySelector.class );
//		final Object interceptorSetting = configurationValues.remove( AvailableSettings.SESSION_INTERCEPTOR );
//		if ( interceptorSetting != null ) {
//			settings.setSessionInterceptorClass(
//					loadSessionInterceptorClass( interceptorSetting, strategySelector )
//			);
//		}
	}
 
Example #18
Source File: BasicOrmDemo.java    From hibernate-demos with Apache License 2.0 6 votes vote down vote up
/**
 * Open session.
 *
 * @return the session
 */
private static Session openSession() {
	if (sessionFactory == null) {
		final Configuration configuration = new Configuration();
		configuration.addAnnotatedClass( User.class );
		configuration.addAnnotatedClass( Tool.class );
		configuration.addAnnotatedClass( Skill.class );
		configuration.addAnnotatedClass( Community.class );
		configuration.addAnnotatedClass( Donation.class );
		configuration.addAnnotatedClass( Comment.class );
		configuration.addAnnotatedClass( ServiceEvent.class );
		configuration.addAnnotatedClass( Project.class );
		
		sessionFactory = configuration.buildSessionFactory( new StandardServiceRegistryBuilder().build() );
	}
	return sessionFactory.openSession();
}
 
Example #19
Source File: HibernateUtil.java    From lambda-rds-mysql with Apache License 2.0 6 votes vote down vote up
public static SessionFactory getSessionFactory() {
    if (null != sessionFactory)
        return sessionFactory;
    
    Configuration configuration = new Configuration();

    String jdbcUrl = "jdbc:mysql://"
            + System.getenv("RDS_HOSTNAME")
            + "/"
            + System.getenv("RDS_DB_NAME");
    
    configuration.setProperty("hibernate.connection.url", jdbcUrl);
    configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
    configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));

    configuration.configure();
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    try {
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    } catch (HibernateException e) {
        System.err.println("Initial SessionFactory creation failed." + e);
        throw new ExceptionInInitializerError(e);
    }
    return sessionFactory;
}
 
Example #20
Source File: HibernateWhereJoinTableIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@BeforeClass
public static void beforeTests() {
    Configuration configuration = new Configuration().addAnnotatedClass(User.class)
        .addAnnotatedClass(Group.class)
        .addAnnotatedClass(UserGroupRelation.class)
        .setProperty("hibernate.dialect", H2Dialect.class.getName())
        .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName())
        .setProperty("hibernate.connection.url", "jdbc:h2:mem:test")
        .setProperty("hibernate.connection.username", "sa")
        .setProperty("hibernate.connection.password", "")
        .setProperty("hibernate.hbm2ddl.auto", "update");
    
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
        .applySettings(configuration.getProperties())
        .build();
    
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
 
Example #21
Source File: HiwayDBNoSQL.java    From Hi-WAY with Apache License 2.0 5 votes vote down vote up
private SessionFactory getSQLSession() {
	try {
		Configuration configuration = new Configuration();
		String url = this.dbURLSQL.substring(0, this.dbURLSQL.lastIndexOf("/")) + "/messungen";
		System.out.println(url);

		configuration.setProperty("hibernate.connection.url", url);
		configuration.setProperty("hibernate.connection.username", this.usernameSQL);
		configuration.setProperty("hibernate.connection.password", this.passwordSQL);
		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", "10");
		configuration.setProperty("hibernate.c3p0.min_size", "5");
		configuration.setProperty("hibernate.c3p0.max_size", "300");
		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", "3000");
		configuration.setProperty("hibernate.c3p0.maxStatementsPerConnection", "20");
		configuration.setProperty("hibernate.c3p0.acquire_increment", "1");
		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);
	}

}
 
Example #22
Source File: SaveMethodsIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeClass
public static void beforeTests() {
    Configuration configuration = new Configuration().addAnnotatedClass(Person.class).setProperty("hibernate.dialect", HSQLDialect.class.getName()).setProperty("hibernate.connection.driver_class", org.hsqldb.jdbcDriver.class.getName())
            .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test").setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "").setProperty("hibernate.hbm2ddl.auto", "update");
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
 
Example #23
Source File: Hbm2ddl.java    From wallride with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	String locationPattern = "classpath:/org/wallride/domain/*";

	final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build();
	final MetadataSources metadataSources = new MetadataSources(registry);
	final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(registry);

	registryBuilder.applySetting(AvailableSettings.DIALECT, ExtendedMySQL5InnoDBDialect.class.getCanonicalName());
	registryBuilder.applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true);
	registryBuilder.applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, PhysicalNamingStrategySnakeCaseImpl.class);

	final PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
	final Resource[] resources = resourcePatternResolver.getResources(locationPattern);
	final SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
	for (Resource resource : resources) {
		MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
		AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
		if (metadata.hasAnnotation(Entity.class.getName())) {
			metadataSources.addAnnotatedClass(Class.forName(metadata.getClassName()));
		}
	}

	final StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) registryBuilder.build();
	final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(registryImpl);

	new SchemaExport()
			.setHaltOnError(true)
			.setDelimiter(";")
			.create(EnumSet.of(TargetType.STDOUT), metadataBuilder.build());
}
 
Example #24
Source File: Reader.java    From Hi-WAY with Apache License 2.0 5 votes vote down vote up
private static SessionFactory getSQLSession(String db) {
	try {
		Configuration configuration = new Configuration();
		System.out.println("connect to: " + db);

		configuration.setProperty("hibernate.connection.url", "jdbc:mysql://127.0.0.1/" + db);
		configuration.setProperty("hibernate.connection.username", "root");
		configuration.setProperty("hibernate.connection.password", "reverse");
		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);
	}
}
 
Example #25
Source File: DdlGeneratorHibernate52.java    From hibernate5-ddl-maven-plugin with GNU General Public License v3.0 5 votes vote down vote up
public PersistenceXmlHandler(
    final StandardServiceRegistryBuilder registryBuilder,
    final Log log,
    final Set<String> propertiesToUse) {

    this.registryBuilder = registryBuilder;
    this.log = log;
    this.propertiesToUse = propertiesToUse;
}
 
Example #26
Source File: HibernateUtils.java    From at.info-knowledge-base with MIT License 5 votes vote down vote up
private static SessionFactory configureSessionFactory(final String dataSource) {
    final Configuration configuration = new Configuration().configure(dataSource);
    final ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(configuration.getProperties()).build();

    return configuration.buildSessionFactory(serviceRegistry);
}
 
Example #27
Source File: ServiceCenterDAO.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
private  SessionFactory configureSessionFactory()
		throws HibernateException {
	Configuration configuration = new Configuration();
	configuration.configure();
	StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
			.applySettings(configuration.getProperties());
	SessionFactory sessionfactory = configuration
			.buildSessionFactory(builder.build());
	return sessionfactory;
}
 
Example #28
Source File: HibernateL2CacheSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @return Hibernate registry builder.
 */
protected StandardServiceRegistryBuilder registryBuilder() {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    return builder;
}
 
Example #29
Source File: AbstractHibernateStorage.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
public AbstractHibernateStorage(HibernateStorageSettings settings) {
    // Init hibernate
    Configuration cfg = new Configuration()
    .setProperty("hibernate.dialect", settings.getDialect())
    .setProperty("hibernate.connection.driver_class", settings.getDriverClass())
    .setProperty("hibernate.connection.url", settings.buildConnectionUrl())
    .setProperty("hibernate.connection.username", settings.getUsername())
    .setProperty("hibernate.connection.password", settings.getPassword())
    .setProperty("hibernate.connection.pool_size", "1")
    
    .setProperty("hibernate.hbm2ddl.auto", "none")
    .setProperty("hibernate.globally_quoted_identifiers", "true")

    .setProperty("show_sql", "false")
    .setProperty("format_sql", "false")
    
    .setProperty("javax.persistence.validation.mode", "none")
    
    // C3P0
    
    .setProperty("hibernate.c3p0.acquire_increment", "1")
    .setProperty("hibernate.c3p0.idle_test_period", "500")
    .setProperty("hibernate.c3p0.max_size", "5")
    .setProperty("hibernate.c3p0.max_statements", "10")
    .setProperty("hibernate.c3p0.min_size", "3")
    .setProperty("hibernate.c3p0.timeout", "100");
    
    configure(settings, cfg);
    
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();

    SessionFactory sessionFactory = cfg.buildSessionFactory(serviceRegistry);
    
    this.storage = new HibernateStorage(sessionFactory);
    
    configure(settings, sessionFactory);
}
 
Example #30
Source File: LoginDAO.java    From primefaces-blueprints with The Unlicense 5 votes vote down vote up
private SessionFactory configureSessionFactory() throws HibernateException {
	Configuration configuration = new Configuration();
	configuration.configure();
	StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
			.applySettings(configuration.getProperties());
	SessionFactory sessionfactory = configuration
			.buildSessionFactory(builder.build());
	return sessionfactory;
}