001    package de.jw.cloud42.core.hibernate;
002    
003    
004    import org.hibernate.*;
005    import org.hibernate.cfg.*;
006    
007    /**
008     * 
009     * Hibernate Util provides access to Hibernate's SessionFactory.
010     * 
011     * This utility class is only used from the webservice application, 
012     * since the webapp uses Seam to integrate Hibernate.
013     * 
014     * @author fbitzer
015     *
016     */
017    public class HibernateUtil {
018    
019        private static final SessionFactory sessionFactory;
020    
021        static {
022            try {
023                // Create the SessionFactory from hibernate.cfg.xml
024                sessionFactory = new  AnnotationConfiguration().configure().buildSessionFactory();
025            } catch (Throwable ex) {
026                // Make sure you log the exception, as it might be swallowed
027                System.err.println("Initial SessionFactory creation failed." + ex);
028                throw new ExceptionInInitializerError(ex);
029            }
030        }
031    
032        public static SessionFactory getSessionFactory() {
033            return sessionFactory;
034        }
035    
036    }