1 package com.iqjava.util; 2 3 import org.hibernate.SessionFactory; 4 import org.hibernate.cfg.AnnotationConfiguration; 5 6 7 public class HibernateUtil { 8 private static final SessionFactory sessionFactory; 9 static { 10 try { 11 sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); 12 } catch (Throwable ex) { 13 System.err.println("Initial SessionFactory creation failed." + ex); 14 throw new ExceptionInInitializerError(ex); 15 } 16 } 17 18 public static SessionFactory getSessionFactory() { 19 return sessionFactory; 20 } 21 }