List of usage examples for org.hibernate.cfg Configuration configure
public Configuration configure() throws HibernateException
From source file:br.fgv.dao.FactorySessionHSqlDB.java
License:Open Source License
public FactorySessionHSqlDB() { if (factory == null) { Configuration cfg = new Configuration(); cfg.configure().setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect") .setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:CGU") .setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver") .setProperty("hibernate.connection.username", "sa") .setProperty("hibernate.connection.password", "").setProperty("hibernate.show_sql", "false"); session = cfg.buildSessionFactory().openSession(); }/*w w w . j a va2 s . co m*/ }
From source file:br.fgv.dao.FactorySessionMySqlDB.java
License:Open Source License
public static Session create() { Session session;/* www . j a va 2s . c o m*/ Configuration cfg = new Configuration(); cfg.configure().setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect") .setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/consultaTSE?autoReconnect=true") .setProperty("hibernate.connection.driver_class", "org.gjt.mm.mysql.Driver") .setProperty("hibernate.connection.username", "root") .setProperty("hibernate.connection.password", "").setProperty("hibernate.show_sql", "false"); session = cfg.buildSessionFactory().openSession(); return session; }
From source file:br.ifes.gerenciadormesada.conexao.HibernateUtil.java
@SuppressWarnings("unused") private static SessionFactory buildSessionFactory() { try {//from w w w. jav a 2s . c om //objeto que armazena configuraes do hibernate.cfg.xml Configuration configuration = new Configuration(); //mtodo que l e valida as configuraes em hibernate.cfg.xml configuration.configure(); //aplica e carrega as configuraes no objeto serviceRegistry //serviceRegistry = (ServiceRegistry) new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry(); serviceRegistry = (ServiceRegistry) new ServiceRegistryBuilder() .applySettings(configuration.getProperties()).build(); //cria uma ou mais instncias de sesso da configurao. Geralmente //uma aplicao tem uma nica instncia de sesso e threads servindo pedidos de clientes //obtendo instncias da sesso do factory (fbrica) sessionFactory = configuration.buildSessionFactory(serviceRegistry); return sessionFactory; } catch (Exception e) { throw new ExceptionInInitializerError("Criacao do objeto falhou: " + e); } }
From source file:ca.myewb.frame.HibernateUtil.java
License:Open Source License
public static Configuration getConfiguration(String suffix) throws IOException { Configuration config = new Configuration(); config = config.configure(); Properties appProperties = new Properties(); java.net.URL url = Thread.currentThread().getContextClassLoader().getResource("app.properties"); InputStream stream = url.openStream(); appProperties.load(stream);/*from w ww.ja v a 2 s. c o m*/ //here we 'add in' the database name, user, password from the application properties file String connString = config.getProperty("hibernate.connection.url") + appProperties.getProperty("dbprefix") + suffix; config.setProperty("hibernate.connection.url", connString); config.setProperty("hibernate.connection.username", appProperties.getProperty("dbuser")); config.setProperty("hibernate.connection.password", appProperties.getProperty("dbpass")); return config; }
From source file:ch.bbw.cms.database.hibernate.HibernateUtil.java
License:GNU General Public License
public HibernateUtil() { Configuration conf = new Configuration(); conf.configure(); serviceRegistry = new ServiceRegistryBuilder().applySettings(conf.getProperties()).buildServiceRegistry(); try {//from w w w .j a v a 2 s . c o m sessionFactory = conf.buildSessionFactory(serviceRegistry); } catch (Exception e) { logger.error("Initial SessionFactory creation failed: ", e); throw new ExceptionInInitializerError(e); } }
From source file:cloudoutput.database.HibernateUtil.java
License:Open Source License
/** * Sets the active database./* w w w . j av a 2 s .com*/ * It changes the active database and builds a new session factory for it. * * @param aActiveDatabase the name of the file that contains the new database. * @see #activeDatabase * @since 1.0 */ public static void setActiveDatabase(String aActiveDatabase) { if (sessionFactory != null) sessionFactory.close(); activeDatabase = aActiveDatabase; Configuration cfg = new Configuration(); cfg.configure(); System.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC"); System.setProperty("hibernate.dialect", "cloudoutput.database.SQLiteDialect"); System.setProperty("hibernate.connection.url", "jdbc:sqlite:db/" + activeDatabase); cfg.setProperties(System.getProperties()); sessionFactory = cfg.buildSessionFactory(); }
From source file:cloudreports.database.HibernateUtil.java
License:Open Source License
/** * Sets the active database./*from ww w.j a v a 2 s. c om*/ * It changes the active database and builds a new session factory for it. * * @param aActiveDatabase the name of the file that contains the new database. * @see #activeDatabase * @since 1.0 */ public static void setActiveDatabase(String aActiveDatabase) { if (sessionFactory != null) sessionFactory.close(); activeDatabase = aActiveDatabase; Configuration cfg = new Configuration(); cfg.configure(); System.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC"); System.setProperty("hibernate.dialect", "cloudreports.database.SQLiteDialect"); System.setProperty("hibernate.connection.url", "jdbc:sqlite:db/" + activeDatabase); cfg.setProperties(System.getProperties()); sessionFactory = cfg.buildSessionFactory(); }
From source file:com.aptech.model.HibernateFactory.java
/** * * @return/* www . j av a 2s. c om*/ * @throws HibernateException */ private static SessionFactory configureSessionFactory() throws HibernateException { Configuration configuration = new Configuration(); configuration.configure(); sessionFactory = configuration.buildSessionFactory(); return sessionFactory; }
From source file:com.arnau.persistencia.hibernate.HibernateUtil.java
public static synchronized void buildSessionFactory() { if (sessionFactory == null) { Configuration configuration = new Configuration(); configuration.configure(); configuration.setProperty("hibernate.current_session_context_class", "thread"); configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder() .applySettings(configuration.getProperties()).buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); }/*from ww w. j a va 2 s .c om*/ }
From source file:com.arnau.persistencia.hibernate.HibernateUtil.java
public static void crearBD() { Configuration configuration = new Configuration(); configuration.configure(); configuration.setProperty("hibernate.current_session_context_class", "thread"); configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); //Si segundo parmetro del mtodo create est a true, Hibernate crea la BD pero borra los datos new org.hibernate.tool.hbm2ddl.SchemaExport(configuration).setOutputFile("script.sql").setDelimiter(";") .create(true, true);//from w w w. j ava 2s . co m }