SHARE
TWEET

Untitled

a guest May 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package utils;
  2.  
  3. import models.Account;
  4. import models.Unit;
  5. import org.hibernate.SessionFactory;
  6. import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  7. import org.hibernate.cfg.Configuration;
  8.  
  9. public class HibernateSessionFactoryUtil {
  10.     private static SessionFactory sessionFactory;
  11.  
  12.     private HibernateSessionFactoryUtil() {}
  13.  
  14.     public static SessionFactory getSessionFactory() {
  15.         if (sessionFactory == null) {
  16.             try {
  17.                 Configuration configuration = new Configuration().configure();
  18.                 configuration.addAnnotatedClass(Account.class);
  19.                 configuration.addAnnotatedClass(Unit.class);
  20.                 StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
  21.                 sessionFactory = configuration.buildSessionFactory(builder.build());
  22.  
  23.             } catch (Exception e) {
  24.                 System.out.println("Исключение!" + e);
  25.             }
  26.         }
  27.         return sessionFactory;
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top