root / trunk / src / java / org / lidar / HibernateUtil.java @ 13
History | View | Annotate | Download (771 Bytes)
1 |
package org.lidar; |
---|---|
2 |
|
3 |
import org.hibernate.SessionFactory; |
4 |
import org.hibernate.cfg.AnnotationConfiguration; |
5 |
|
6 |
/**
|
7 |
*
|
8 |
* @author Andrej Cimpersek
|
9 |
*/
|
10 |
public class HibernateUtil { |
11 |
|
12 |
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 |
} |
24 |
|
25 |
public static SessionFactory getSessionFactory() { |
26 |
return sessionFactory;
|
27 |
} |
28 |
} |