Created
April 17, 2015 16:55
-
-
Save nunenuh/9aecfaec7f32764392b0 to your computer and use it in GitHub Desktop.
HibernateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package epserv.orm.utils; | |
import java.io.File; | |
import org.hibernate.cfg.AnnotationConfiguration; | |
import org.hibernate.SessionFactory; | |
/** | |
* Hibernate Utility class with a convenient method to get Session Factory object. | |
* | |
* @author rozee | |
*/ | |
public class HibernateUtil { | |
private static final SessionFactory sessionFactory; | |
static { | |
try { | |
// Create the SessionFactory from standard (hibernate.cfg.xml) | |
// config file. | |
String configFile="conf/hibernate.cfg.xml"; | |
String path = System.getProperty("user.dir"); | |
path = path +"/"+configFile; | |
sessionFactory = new AnnotationConfiguration().configure(new File(path)).buildSessionFactory(); | |
} catch (Throwable ex) { | |
// Log the exception. | |
System.err.println("Exception stack Trace ************** begin"); | |
System.err.println("Hibernate : Initial SessionFactory creation failed." + ex); | |
ex.printStackTrace(); | |
System.err.println("Exception Stack Trace ********* END"); | |
throw new ExceptionInInitializerError(ex); | |
} | |
} | |
public static SessionFactory getSessionFactory() { | |
return sessionFactory; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment