Advertisement
tadeuespindola

HibernateUtil.java

Feb 28th, 2021
1,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. package java_hibernate.java_hibernate;
  2.  
  3. import javax.persistence.EntityManager;
  4. import javax.persistence.EntityManagerFactory;
  5. import javax.persistence.Persistence;
  6.  
  7. public class HibernateUtil {
  8.    
  9.     public static EntityManagerFactory factory = null;
  10.    
  11.     static {
  12.         init();
  13.     }
  14.    
  15.     private static void init() {
  16.         try {          
  17.             if(factory == null) {
  18.                 factory = Persistence.createEntityManagerFactory("java-hibernate");
  19.             }          
  20.         } catch (Exception e) {
  21.             e.printStackTrace();
  22.         }
  23.     }
  24.    
  25.     public static EntityManager getEntityManager() {
  26.         return factory.createEntityManager(); /* Provê persistência*/
  27.     }  
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement