package net.netbauds.catalina;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
// 单态的 sessionFactory
public class HibernateSessionFactory {
PRivate static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
// 不要从 JNDI中获取SessionFactory, 使用一个静态的 SessionFactory
if (sessionFactory == null ) {
Configuration conf = new Configuration();
try {
Class klass = Class.forName( " config.HibernateCachableFileLoad " );
IHibernateCachableFileLoad hibConf = (IHibernateCachableFileLoad) klass.newInstance();
hibConf.addMappings(conf);
} catch (ClassNotFoundException e) {
// NOOP
} catch (InstantiationException e) {
// NOOP
} catch (Illegal
accessException e) {
// NOOP
}
Configuration confdone = conf.configure();
if (confdone != null ) {
// Use default hibernate.cfg.xml
sessionFactory = confdone.buildSessionFactory();
}
}
return sessionFactory;
}
}