package src.hibernatebb.discussion;

import org.hibernate.*;
import org.hibernate.cfg.*;

/**
 * The Hibernate Util class is a singleton that manages the 
 * necessary hibernate configuration and startup.
 * 
 * @author Peter Deschere
 * @author David Nonne
 * @version 1.0
 * @see <a>http://www.hibernate.org</a>
 */
public class HibernateUtil { 
	private static final SessionFactory sessionFactory;
	
	static {
		try { 
			// Create the SessionFactory from hibernate.cfg.xml
			sessionFactory = new Configuration().configure().buildSessionFactory();
			} catch (Throwable ex) { 
			// Make sure you log the exception, as it might be swallowed
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	} 
	
	/**
	 * Calls  the session factory to get the current session.
	 * 
	 * @return the Session factory to get the current session
	 */
	public static SessionFactory getSessionFactory() { return sessionFactory; }
}
