Created
April 21, 2020 06:13
-
-
Save Pudding124/5b84c46a49f0c9e1752bb4aa2a8fc1c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package util; | |
import org.hibernate.SessionFactory; | |
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | |
import org.hibernate.cfg.Configuration; | |
import org.hibernate.service.ServiceRegistry; | |
public class HibernateUtil { | |
private static SessionFactory sessionFactory; | |
static { | |
try { | |
Configuration configuration = new Configuration(); | |
configuration.configure(); | |
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings( | |
configuration.getProperties()).build(); | |
sessionFactory = configuration.buildSessionFactory(serviceRegistry); | |
} catch (Throwable ex) { | |
throw new ExceptionInInitializerError(ex); | |
} | |
} | |
public static SessionFactory getSessionFactory() { | |
return sessionFactory; | |
} | |
public static void shutdown() { | |
getSessionFactory().close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment