1 | |
package booking.model.util; |
2 | |
|
3 | |
import org.hibernate.SessionFactory; |
4 | |
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
5 | |
import org.hibernate.cfg.Configuration; |
6 | |
import org.hibernate.service.ServiceRegistry; |
7 | |
|
8 | 0 | public class HibernateUtil { |
9 | |
|
10 | 1 | private static final SessionFactory sessionFactory = buildSessionFactory(); |
11 | |
|
12 | |
private static SessionFactory buildSessionFactory() { |
13 | |
try { |
14 | |
|
15 | |
|
16 | 1 | Configuration configuration = new Configuration(); |
17 | 1 | configuration.configure("hibernate.cfg.xml"); |
18 | |
|
19 | 1 | ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings( |
20 | |
configuration.getProperties()).build(); |
21 | |
|
22 | 1 | return configuration.buildSessionFactory(serviceRegistry); |
23 | 0 | } catch (Throwable ex) { |
24 | |
|
25 | 0 | System.err.println("Initial SessionFactory creation failed." + ex); |
26 | 0 | throw new ExceptionInInitializerError(ex); |
27 | |
} |
28 | |
} |
29 | |
|
30 | |
public static SessionFactory getSessionFactory() { |
31 | 5 | return sessionFactory; |
32 | |
} |
33 | |
|
34 | |
} |