/web/DRCP/src/util/HibernateUtil.java

http://drcp.googlecode.com/ · Java · 27 lines · 18 code · 7 blank · 2 comment · 0 complexity · 1cc874e06e4ee6a4cf6fe47b42e3e78a MD5 · raw file

  1. package util;
  2. import org.hibernate.SessionFactory;
  3. import org.hibernate.cfg.Configuration;
  4. public class HibernateUtil {
  5. private static final SessionFactory sessionFactory;
  6. static {
  7. try {
  8. // Create the SessionFactory from hibernate.cfg.xml
  9. Configuration cfg = new Configuration().configure();
  10. sessionFactory = cfg.buildSessionFactory();
  11. } catch (Throwable ex) {
  12. // Make sure you log the exception, as it might be swallowed
  13. System.err.println("Initial SessionFactory creation failed." + ex);
  14. throw new ExceptionInInitializerError(ex);
  15. }
  16. }
  17. public static SessionFactory getSessionFactory() {
  18. return sessionFactory;
  19. }
  20. }