Example usage for org.hibernate.cfg Configuration setProperty

List of usage examples for org.hibernate.cfg Configuration setProperty

Introduction

In this page you can find the example usage for org.hibernate.cfg Configuration setProperty.

Prototype

public Configuration setProperty(String propertyName, String value) 

Source Link

Document

Set a property value by name

Usage

From source file:ar.com.pahema.hibernate.HibernateUtilWEB.java

public static synchronized void buildSessionFactory() {
    if (sessionFactory == null) {
        Configuration configuration = new Configuration();
        configuration.configure(archivoConfiguracion);
        configuration.setProperty("hibernate.current_session_context_class", "thread");
        org.hibernate.service.ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).buildServiceRegistry();
        sessionFactory = configuration//from  w w  w.  j  ava 2  s  . co m
                .buildSessionFactory((org.hibernate.service.ServiceRegistry) serviceRegistry);
    }
}

From source file:at.oculus.teamf.databaseconnection.session.HibernateSessionBroker.java

License:Open Source License

/**
 * Creates a new {@code #HibernateSessionBroker}
 *
 * @param clazzes annotated classes to configure the hibernate session factory
 *///from   w  w w  .j  a  va  2s.co m
public HibernateSessionBroker(Collection<Class> clazzes) {
    Configuration configuration = new Configuration();

    HibernateProperties ph = new HibernateProperties("config.properties");

    configuration.setProperty("hibernate.connection.url", ph.getURL());
    configuration.setProperty("hibernate.connection.driver_class", ph.getDriver());
    configuration.setProperty("hibernate.connection.username", ph.getUser());
    configuration.setProperty("hibernate.connection.password", ph.getPassword());

    _clazzes = clazzes;
    for (Class clazz : clazzes) {
        configuration.addAnnotatedClass(clazz);
    }

    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
            .buildServiceRegistry();
    _sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    //reason for the double connection!
    Map<String, Object> configOverrides = new HashMap<String, Object>();
    configOverrides.put("hibernate.connection.url", ph.getURL());
    configOverrides.put("hibernate.connection.driver_class", ph.getDriver());
    configOverrides.put("hibernate.connection.username", ph.getUser());
    configOverrides.put("hibernate.connection.password", ph.getPassword());
    _entityManagerFactory = Persistence.createEntityManagerFactory("oculus_f", configOverrides);
}

From source file:at.stefanproell.PersistentIdentifierMockup.HibernateSchemaGeneratorPID.java

License:Apache License

public static void main(String[] args) {

    String outputFilePath = "PersistentIdentification/additional_configuration/PID-Hibernate-schema.sql";

    Configuration config = new Configuration();
    config.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    config.addAnnotatedClass(PersistentIdentifier.class);
    config.addAnnotatedClass(Organization.class);
    SchemaExport export = new EnversSchemaGenerator(config).export().setOutputFile(outputFilePath);
    export.setDelimiter(";");
    export.execute(true, false, false, false);

    // Update Schema
    //updateSchema(config);
}

From source file:au.edu.anu.metadatastores.harvester.HarvesterHibernateUtil.java

License:Open Source License

/**
 * Build the sesion factory//from   w  ww .j a v a  2  s.c  o  m
 * 
 * @return The session factory
 */
private static SessionFactory buildSessionFactory() {
    try {
        Configuration configuration = new Configuration();
        configuration.configure("/harvester.cfg.xml");

        //Provide for having an encrypted password
        String password = configuration.getProperty("hibernate.connection.password");
        String decryptedValue = EncryptUtil.decrypt(password);
        configuration.setProperty("hibernate.connection.password", decryptedValue);

        ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder()
                .applySettings(configuration.getProperties());

        return configuration.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
    } catch (Exception e) {
        LOGGER.error("Initial SessionFactory creation failed.", e);
        throw new ExceptionInInitializerError(e);
    }
}

From source file:au.edu.anu.metadatastores.services.aries.AriesHibernateUtil.java

License:Open Source License

/**
 * Create the session factory//from   ww  w  .  j  a va 2 s .  c  om
 * 
 * @return The session factory
 */
private static SessionFactory buildSessionFactory() {
    try {
        Configuration configuration = new Configuration();
        configuration.configure("/aries.cfg.xml");

        //Provide for having an encrypted password
        String password = configuration.getProperty("hibernate.connection.password");
        if (password != null) {
            String decryptedValue = EncryptUtil.decrypt(password);
            configuration.setProperty("hibernate.connection.password", decryptedValue);
        }

        ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder()
                .applySettings(configuration.getProperties());

        return configuration.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
    } catch (Exception e) {
        LOGGER.error("Initial SessionFactory creation failed.", e);
        throw new ExceptionInInitializerError(e);
    }
}

From source file:au.edu.anu.metadatastores.services.store.StoreHibernateUtil.java

License:Open Source License

/**
 * Create the session factory//from  w  ww. j  a v  a  2  s  .com
 * 
 * @return The session factory
 */
private static SessionFactory buildSessionFactory() {
    try {
        Configuration configuration = new Configuration();
        configuration.configure("/store.cfg.xml");

        //Provide for having an encrypted password
        String password = configuration.getProperty("hibernate.connection.password");
        String decryptedValue = EncryptUtil.decrypt(password);
        configuration.setProperty("hibernate.connection.password", decryptedValue);
        ServiceRegistryBuilder serviceRegistryBuilder = new ServiceRegistryBuilder()
                .applySettings(configuration.getProperties());
        return configuration.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
    } catch (Exception e) {
        LOGGER.error("Initial SessionFactory creation failed.", e);
        throw new ExceptionInInitializerError(e);
    }
}

From source file:backend.core.controller.ProductsController.java

public static SessionFactory getInstance() {

    if (sf == null) {

        Configuration cfg = new Configuration();
        cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
        cfg.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
        cfg.setProperty("hibernate.connection.url", "jdbc:mysql://db4free.net:3306/iomarket");
        cfg.setProperty("hibernate.connection.username", "iomarket");
        cfg.setProperty("hibernate.connection.password", "iomarket123");
        cfg.setProperty("hibernate.hbm2ddl.auto", "update");

        cfg.setProperty("show_sql", "true");

        cfg.addResource("Products.hbm.xml");
        cfg.addResource("Suppliers.hbm.xml");
        cfg.addResource("Attributes.hbm.xml");
        cfg.addResource("AttrValues.hbm.xml");
        cfg.addResource("Category.hbm.xml");
        cfg.addResource("Users.hbm.xml");
        cfg.addResource("Orders.hbm.xml");
        cfg.addResource("Groups.hbm.xml");
        cfg.addResource("Monitoring.hbm.xml");
        cfg.addResource("MonitoringWorkers.hbm.xml");

        sf = cfg.buildSessionFactory();/*  w ww .  jav  a 2  s .c  o m*/
    }

    return sf;
}

From source file:backend.core.controller.UserController.java

public static SessionFactory getInstance() {

    if (sf == null) {

        Configuration cfg = new Configuration();
        cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
        cfg.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
        cfg.setProperty("hibernate.connection.url", "jdbc:mysql://localhost/io");
        cfg.setProperty("hibernate.connection.username", "root");
        cfg.setProperty("hibernate.connection.password", "");
        cfg.setProperty("hibernate.hbm2ddl.auto", "update");

        cfg.setProperty("show_sql", "true");

        cfg.addResource("Groups.hbm.xml");
        cfg.addResource("Users.hbm.xml");

        sf = cfg.buildSessionFactory();/*w w  w .  j  ava  2  s  .  co  m*/
    }

    return sf;
}

From source file:br.com.sinax.musicpoc.Bootstrap.java

License:Apache License

/**
 * Builds the persistance./*ww  w.  j a  v  a 2  s  . c o  m*/
 */
private void buildPersistance() {

    // Build Hibernate Configuration
    Configuration configuration = new Configuration();

    configuration.addAnnotatedClass(Music.class);
    configuration.setProperty("hibernate.connection.driver_class", "org.h2.Driver");
    configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:test_mem;");
    configuration.setProperty("hibernate.connection.username", "");
    configuration.setProperty("hibernate.connection.password", "");
    configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    configuration.setProperty("hibernate.hbm2ddl.auto", "update");
    configuration.setProperty("hibernate.show_sql", "true");
    configuration.setProperty("hibernate.connection.pool_size", "3");

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

    // Registry on Container
    registryComponent(MusicDaoImpl.class);
    registryComponent(new HibernateSessionProviderImpl(sessionFactory));
}

From source file:br.gov.jfrj.siga.dp.dao.CpDao.java

License:Open Source License

static public Configuration criarHibernateCfg(String datasource) throws Exception {

    Configuration cfg = new Configuration();
    cfg.setProperty("hibernate.connection.datasource", datasource);

    return configurarHibernate(cfg);
}