Skip to content

Instantly share code, notes, and snippets.

@shankybnl
Created June 6, 2018 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shankybnl/43d2801783b6123f7fb0237d053d993e to your computer and use it in GitHub Desktop.
Save shankybnl/43d2801783b6123f7fb0237d053d993e to your computer and use it in GitHub Desktop.
HibernateUtil.java
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
Configuration cfg = new Configuration();
cfg.setProperty("hibernate.connection.url", CommonUtil.loadTestData.getString("connection.url"));
cfg.setProperty("hibernate.connection.username", CommonUtil.loadTestData.getString("connection.username"));
cfg.setProperty("hibernate.connection.password", CommonUtil.loadTestData.getString("connection.password"));
cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
cfg.configure();
sessionFactory = cfg.buildSessionFactory();
} catch (Throwable ex) {
System.err.println("SessionFactory creation failed" + ex);
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