root / trunk / src / java / org / lidar / HibernateUtil.java @ 9
History | View | Annotate | Download (713 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 | public class HibernateUtil { |
||
12 | private static final SessionFactory sessionFactory; |
||
13 | static {
|
||
14 | try {
|
||
15 | // Create the SessionFactory from hibernate.cfg.xml
|
||
16 | sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
|
||
17 | } catch (Throwable ex) { |
||
18 | // Make sure you log the exception, as it might be swallowed
|
||
19 | System.err.println("Initial SessionFactory creation failed." + ex); |
||
20 | throw new ExceptionInInitializerError(ex); |
||
21 | } |
||
22 | } |
||
23 | |||
24 | public static SessionFactory getSessionFactory() { |
||
25 | return sessionFactory;
|
||
26 | } |
||
27 | } |