Last active
December 10, 2015 05:29
-
-
Save rahulshivsharan/4388343 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment