Example usage for org.hibernate.cfg Configuration Configuration

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

Introduction

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

Prototype

public Configuration() 

Source Link

Usage

From source file:com.github.aint.jblog.model.util.HibernateUtil.java

License:Open Source License

private static SessionFactory buildSessionFactory() {
    try {//from  w ww .  j  a  v  a2 s .c  om
        return new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Initial SessionFactory creation failed. " + ex.getClass() + " " + ex.getMessage());
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:com.github.aint.jblog.service.util.HibernateUtil.java

License:Open Source License

private static SessionFactory buildSessionFactory() {
    try {// ww  w  .j  a v a2s . com
        return new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) {
        logger.error("Initial SessionFactory creation failed. {} {}", ex.getClass(), ex.getMessage());
        throw new ExceptionInInitializerError(ex);
    }
}

From source file:com.github.leonardoxh.temporeal.model.hibernate.HibernateUtils.java

License:Apache License

private static SessionFactory buildSessionFactory() {
    Configuration configuration = new Configuration();
    configuration.configure();/*w  w w.j a v a2  s .  com*/
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build();
    return configuration.buildSessionFactory(serviceRegistry);
}

From source file:com.github.patrickianwilson.blogs.testing.induction.repositories.MySQLURLRepository.java

License:Open Source License

public MySQLURLRepository() {
    cfg = new Configuration().configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();

    sessionFactory = cfg.buildSessionFactory(serviceRegistry);
}

From source file:com.github.patrickianwilson.blogs.testing.induction.repositories.MySQLURLRepositoryTests.java

License:Open Source License

@Before()
public void setup() {
    cfg = new Configuration().configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();

    sessionFactory = cfg.buildSessionFactory(serviceRegistry);
}

From source file:com.github.shyiko.rook.target.hibernate.cache.AbstractHibernateTest.java

License:Apache License

@BeforeClass
public void setUp() throws SQLException {
    Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
    ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties())
            .buildServiceRegistry();//from  ww  w .  jav  a  2 s. co  m
    SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    synchronizationContext = new SynchronizationContext(configuration, sessionFactory);
}

From source file:com.glaf.jbpm.util.HibernateUtils.java

License:Apache License

public static Configuration createHibernateConfiguration() {
    try {//from  w  ww . j av a 2 s. c o m
        JbpmConfiguration cfg = new JbpmConfiguration();
        cfg.config();
        Thread.sleep(1000);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    Configuration configuration = new Configuration();
    String filename = SystemProperties.getConfigRootPath() + "/conf/jbpm/hibernate.cfg.xml";
    File cfgUrl = new File(filename);
    configuration.configure(cfgUrl);
    return configuration;
}

From source file:com.globalsight.ling.tm3.tools.TM3Command.java

License:Apache License

protected SessionFactory getSessionFactory(CommandLine command) {
    String username = null, password = null, connStr = null;
    // Order of operations:
    // - start with defaults
    // - load the file specified with -properties (if set), or the
    // default properties file.
    // - Look for command line options to override.
    if (command.hasOption(PROPERTIES)) {
        loadPropertiesFromFile(properties, command.getOptionValue(PROPERTIES), true);
    } else {/*from  w ww. j a  v  a2 s. co m*/
        loadDefaultProperties(properties);
    }
    // Override any file properties with things passed on the command line
    Properties overrideProps = command.getOptionProperties(PROPERTY);
    for (Map.Entry<Object, Object> e : overrideProps.entrySet()) {
        properties.setProperty((String) e.getKey(), (String) e.getValue());
    }

    username = properties.getProperty(TM3_USER_PROPERTY);
    password = properties.getProperty(TM3_PASSWORD_PROPERTY);
    connStr = properties.getProperty(TM3_CONNECTION_PROPERTY);
    if (username == null || password == null || connStr == null) {
        usage("Must specify " + TM3_USER_PROPERTY + ", " + TM3_PASSWORD_PROPERTY + ", and "
                + TM3_CONNECTION_PROPERTY + " with -Dprop=val or via properties file");
    }

    Properties hibernateProps = new Properties(properties);
    hibernateProps.put("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");
    hibernateProps.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
    hibernateProps.put("hibernate.connection.url", connStr);
    hibernateProps.put("hibernate.connection.username", username);
    hibernateProps.put("hibernate.connection.password", password);
    hibernateProps.put("hibernate.cglib.use_reflection_optimizer", "false"); // this
                                                                             // is
                                                                             // default
                                                                             // in
                                                                             // hibernate
                                                                             // 3.2
    hibernateProps.put("hibernate.show_sql", "false");
    hibernateProps.put("hibernate.format_sql", "false");
    hibernateProps.put("hibernate.connection.pool_size", "1");
    hibernateProps.put("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");
    // A little sketchy. Due to some undocumented (?) Hibernate
    // behavior, it will pick up hibernate cfg properties from elsewhere
    // in the classpath, even though we've specified them by hand.
    // As a result, this may end up unintentionally running c3p0
    // connection pooling, which will release connections on commit.
    // This causes problems for multi-transaction commands (like
    // GlobalSight's migrate-tm), because it will kill the connection
    // in mid-operation. As a result, we force the release mode to
    // keep the connection open until we're done.
    hibernateProps.put("hibernate.connection.release_mode", "on_close");
    Configuration cfg = new Configuration().addProperties(hibernateProps);
    cfg = HibernateConfig.extendConfiguration(cfg);
    if (requiresDataFactory()) {
        cfg = getDataFactory().extendConfiguration(cfg);
    }

    return cfg.buildSessionFactory();
}

From source file:com.gluo.webchat.maven.utilities.HibernateUtil.java

private static SessionFactory initFactory() {
    try {/*from   w  w w. j a va 2 s. c om*/
        return new Configuration().configure().buildSessionFactory();
    } catch (Throwable ex) {
        System.err.println("Failed to create sessionFactory object." + ex);
        return null;
    }
}

From source file:com.googlecode.sarasvati.example.hib.HibTestSetup.java

License:Open Source License

public static void init(final boolean createSchema) throws Exception {
    final Configuration config = new Configuration();

    if (createSchema) {
        config.setProperty(Environment.HBM2DDL_AUTO, "create-drop");
    }/*from   w  w w. j  a va 2s  .  c o m*/

    HibEngine.addToConfiguration(config, false);

    config.addAnnotatedClass(HibExampleTaskNode.class);
    config.addAnnotatedClass(Task.class);
    config.addAnnotatedClass(InitNode.class);
    config.addAnnotatedClass(DumpNode.class);
    config.addAnnotatedClass(AsyncNode.class);

    URL url = HibTestSetup.class.getClassLoader().getResource("hibernate.cfg.xml");

    if (url == null) {
        System.out.println("ERROR: No hibernate.cfg.xml found in classpath!\n"
                + "\tIn order to run the examples, you must create hibernate.cfg.xml in the examples/ directory.\n"
                + "\tYou can use the entries in conf/ as a starting point.");
        System.exit(-1);
    }

    config.configure(url);
    sessionFactory = config.buildSessionFactory();
}