Mercurial > hg > LGServices
diff src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java @ 0:3e62083dbcbf
First commit. This project comes from LGServer. We removed the framework icefaces. Now, LGServices uses just JSP and jquery.
author | "jurzua <jurzua@mpiwg-berlin.mpg.de>" |
---|---|
date | Thu, 23 Apr 2015 15:46:01 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java Thu Apr 23 15:46:01 2015 +0200 @@ -0,0 +1,31 @@ +package de.mpiwg.gazetteer.utils; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AnnotationConfiguration; + + +public class HibernateUtil { + + private static final SessionFactory sessionFactory; + + static { + try { + // Create the SessionFactory from hibernate.cfg.xml + AnnotationConfiguration cfg = new AnnotationConfiguration().configure("hibernate.cfg.xml"); + if(System.getProperty("hibernate.hbm2ddl.auto") != null && System.getProperty("hibernate.hbm2ddl.auto").equals("create")){ + cfg.setProperty("hibernate.hbm2ddl.auto", "create"); + } + 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); + ex.printStackTrace(); + throw new ExceptionInInitializerError(ex); + } + } + + public static SessionFactory getSessionFactory() { + return sessionFactory; + } + +} \ No newline at end of file