Last active
December 10, 2015 05:29
-
-
Save rahulshivsharan/4388343 to your computer and use it in GitHub Desktop.
Revisions
-
rahulshivsharan renamed this gist
Dec 27, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
rahulshivsharan created this gist
Dec 27, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ package sdf.common.sf; import java.util.HashMap; import java.util.Map; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; public enum HibernateCon { INSTANCE; private SessionFactory sessionFactory; private HibernateCon(){ System.out.println(" IN ENUM HibernateCon "); sessionFactory = buildFactory(); } private SessionFactory buildFactory(){ SessionFactory sf = null; Configuration cfg = null; ServiceRegistry serviceReg = null; ServiceRegistryBuilder serviceRegBuilder = null; Map<String, String> map = null; try{ cfg = new Configuration(); map = new HashMap<String, String>(); map.put("hibernate.connection.driver_class", "org.apache.derby.jdbc.ClientDriver"); map.put("hibernate.connection.url", "jdbc:derby://localhost:1527/sun-appserv-samples"); map.put("hibernate.connection.username", "APP"); map.put("hibernate.connection.password", "app"); map.put("hibernate.dialect", "org.hibernate.dialect.DerbyDialect"); map.put("hibernate.show_sql", "true"); map.put("hibernate.format_sql", "true"); cfg.addResource("Student.hbm.xml"); serviceRegBuilder = new ServiceRegistryBuilder(); serviceReg = serviceRegBuilder.applySettings(map).buildServiceRegistry(); sf = cfg.buildSessionFactory(serviceReg); }catch(Exception e){ System.out.println(" EXCEPTION WHILE BUILDING SESSION-FACTORY "); e.printStackTrace(); } return sf; } public SessionFactory getSessionFactory(){ return this.sessionFactory; } }