01: package util;
02:
03: import org.hibernate.*;
04: import org.hibernate.cfg.*;
05:
06: public class HibernateUtil {
07:
08: private static final SessionFactory sessionFactory;
09:
10: static {
11: try {
12: // Create the SessionFactory from hibernate.cfg.xml
13: sessionFactory = new Configuration().configure()
14: .buildSessionFactory();
15: } catch (Throwable ex) {
16: // Make sure you log the exception, as it might be swallowed
17: System.err
18: .println("Initial SessionFactory creation failed."
19: + ex);
20: throw new ExceptionInInitializerError(ex);
21: }
22: }
23:
24: public static SessionFactory getSessionFactory() {
25: return sessionFactory;
26: }
27:
28: }
|