Mercurial > hg > LGServices
view src/main/java/de/mpiwg/gazetteer/utils/HibernateUtil.java @ 50:8f6c47775fe8
new: 'view on LGMap' shown on the existing full text searching list
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 26 Jan 2016 13:41:47 +0100 |
parents | 3e62083dbcbf |
children |
line wrap: on
line source
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; } }