Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package projetohibernate;
  7.  
  8. import org.hibernate.cfg.AnnotationConfiguration;
  9. import org.hibernate.SessionFactory;
  10.  
  11. /**
  12. * Hibernate Utility class with a convenient method to get Session Factory
  13. * object.
  14. *
  15. * @author Nicolau
  16. */
  17. public class HibernateUtil {
  18.  
  19. private static final SessionFactory sessionFactory;
  20.  
  21. static {
  22. try {
  23. // Create the SessionFactory from standard (hibernate.cfg.xml)
  24. // config file.
  25. sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
  26. } catch (Throwable ex) {
  27. // Log the exception.
  28. System.err.println("Initial SessionFactory creation failed." + ex);
  29. throw new ExceptionInInitializerError(ex);
  30. }
  31. }
  32.  
  33. public static SessionFactory getSessionFactory() {
  34. return sessionFactory;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement