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 entidades.util; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; /** * Hibernate Utility class with a convenient method to get Session Factory * object. * * @author andres */ public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); return cfg.buildSessionFactory(); } catch (Throwable e) { System.out.println("Error: " + e); throw new ExceptionInInitializerError(e); } } public static SessionFactory getSessionFactory() { return sessionFactory; } }