Example usage for org.hibernate.cfg Configuration getProperty

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

Introduction

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

Prototype

public String getProperty(String propertyName) 

Source Link

Document

Get a property value by name

Usage

From source file:org.xchain.framework.hibernate.HibernateLifecycle.java

License:Apache License

private static void setXChainDefaults(QName name, Configuration configuration) {
    String dataSourceJndi = configuration.getProperty(Environment.DATASOURCE);
    String connectionProvider = configuration.getProperty(Environment.CONNECTION_PROVIDER);

    if (dataSourceJndi != null && connectionProvider == null) {
        if (log.isInfoEnabled()) {
            log.info("Adding the property '" + Environment.CONNECTION_PROVIDER
                    + "' with value 'org.xchain.framework.hibernate.RebindingDataSourceConnectionProvider' to the hibernate configuration of datasource '"
                    + dataSourceJndi + "'.");
        }/*w ww.  j ava2 s.c o  m*/
        configuration.setProperty(Environment.CONNECTION_PROVIDER,
                "org.xchain.framework.hibernate.RebindingDataSourceConnectionProvider");
    }
}

From source file:sanger.team16.common.jdbc.AbstractJDBC.java

License:Open Source License

public AbstractJDBC(String address) {
    this.address = address;
    Configuration cfg = new Configuration().configure(address);
    String driver = cfg.getProperty("hibernate.connection.driver_class");
    String url = cfg.getProperty("hibernate.connection.url");
    String username = cfg.getProperty("hibernate.connection.username");
    String password = cfg.getProperty("connection.password");

    try {//from  ww  w .  j a  v a2 s.  c o m
        Class.forName(driver);
        conn = DriverManager.getConnection(url, username, password);

    } catch (SQLException e) {

    } catch (ClassNotFoundException e) {
    }
}

From source file:srcclasses.HibernateUtilHelper.java

private static SessionFactory initHibernate() {
    try {//w ww.j av  a  2s .com
        // Create the SessionFactory from hibernate.cfg.xml
        final Configuration config = new Configuration().configure("hibernate.cfg.xml");
        LOG.info("Connection hibernate to URL=" + config.getProperty("hibernate.connection.url"));
        StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(config.getProperties()).build();

        return config.buildSessionFactory(serviceRegistry);
    } catch (Throwable ex) {
        // log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed. " + ex);
        throw new ExceptionInInitializerError(ex);
    }

}

From source file:tests.ReadHibernateConfig.java

public static void main(String[] args) {
    Configuration config = new Configuration();
    config.configure("hibernate.cfg.xml");
    System.out.println("db username: " + config.getProperty("hibernate.connection.username"));
    System.out.println("db password: " + config.getProperty("hibernate.connection.password"));
    System.out.println("url: " + config.getProperty("hibernate.connection.url"));
}