package com.pb.hibernate.util;
importjava.sql.SQLException;
importorg.hibernate.HibernateException;
importorg.hibernate.Session;
importorg.hibernate.SessionFactory;
importorg.hibernate.cfg.Configuration;
public class HibernateSessionFactory{
private static StringCONFIG_FILE_LOCATION ="/com/hibernate/hibernate.cfg.xml";
private static finalThreadLocal threadLocal = newThreadLocal();
private static Configuration configuration = newConfiguration();
privatestatic SessionFactorysessionFactory;
privatestatic String configFile =CONFIG_FILE_LOCATION;
privateHibernateSessionFactory(){
}
publicstatic Session getCurrentSession() throws HibernateException{
Session session = (Session)threadLocal.get();
try {
if (session == null || !session.isOpen()||session.connection().isClosed()){
if (sessionFactory == null){
rebuildSessionFactory();
}
session = (sessionFactory != null) ?sessionFactory.openSession()
: null;
threadLocal.set(session);
}
} catch (SQLException e){
// TODO Auto-generated catchblock