Project

General

Profile

Statistics
| Revision:

root / trunk / src / java / org / lidar / HibernateUtil.java @ 12

History | View | Annotate | Download (771 Bytes)

1 9 andrej.cim
package org.lidar;
2
3
import org.hibernate.SessionFactory;
4
import org.hibernate.cfg.AnnotationConfiguration;
5
6
/**
7
 *
8
 * @author Andrej Cimpersek
9
 */
10 11 andrej.cim
public class HibernateUtil {
11 9 andrej.cim
12 11 andrej.cim
    private static final SessionFactory sessionFactory;
13
14
    static {
15
        try {
16
            // Create the SessionFactory from hibernate.cfg.xml
17
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
18
        } catch (Throwable ex) {
19
            // Make sure you log the exception, as it might be swallowed
20
            System.err.println("Initial SessionFactory creation failed." + ex);
21
            throw new ExceptionInInitializerError(ex);
22
        }
23 9 andrej.cim
    }
24
25 11 andrej.cim
    public static SessionFactory getSessionFactory() {
26
        return sessionFactory;
27
    }
28
}