Guest User

Untitled

a guest
Jan 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package ru.ifmo.lab3.database;
  2.  
  3.  
  4. import org.hibernate.SessionFactory;
  5. import org.hibernate.cfg.Configuration;
  6.  
  7. public class HibernateUtil {
  8. private static final SessionFactory sessionFactory = buildSessionFactory();
  9.  
  10. private static SessionFactory buildSessionFactory() {
  11. try {
  12. return new Configuration().configure().buildSessionFactory();
  13. } catch (Throwable ex) {
  14. System.err.println("Initial SessionFactory creation failed." + ex);
  15. throw new ExceptionInInitializerError(ex);
  16. }
  17. }
  18.  
  19. public static SessionFactory getSessionFactory() {
  20. return sessionFactory;
  21. }
  22.  
  23. public static void shutdown() {
  24. getSessionFactory().close();
  25. }
  26. }
Add Comment
Please, Sign In to add comment