/web/DRCP/src/util/HibernateUtil.java
http://drcp.googlecode.com/ · Java · 27 lines · 18 code · 7 blank · 2 comment · 0 complexity · 1cc874e06e4ee6a4cf6fe47b42e3e78a MD5 · raw file
- package util;
-
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.Configuration;
-
- public class HibernateUtil {
-
- private static final SessionFactory sessionFactory;
-
- static {
- try {
- // Create the SessionFactory from hibernate.cfg.xml
- Configuration cfg = new Configuration().configure();
- sessionFactory = cfg.buildSessionFactory();
-
- } catch (Throwable ex) {
- // Make sure you log the exception, as it might be swallowed
- System.err.println("Initial SessionFactory creation failed." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- }
-
- public static SessionFactory getSessionFactory() {
- return sessionFactory;
- }
-
- }