Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package br.com.magmadoctor.util; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; /** * * @author Dirceu Junior */ public class HibernateUtil { //private static final SessionFactory sessionFactory; private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); return cfg.buildSessionFactory(); //return cfg.buildSessionFactory(null); } catch (Throwable e) { System.out.println("Criao inicial do objeto SessionFactory falhou. Erro: " + e); throw new ExceptionInInitializerError(e); } } public static SessionFactory getSessionFactory() { return sessionFactory; } }