tadeuespindola

HibernateUtil.java

Feb 28th, 2021
745
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×