Last active
August 29, 2015 14:20
-
-
Save dalmat36/29d19f41f57b0247cb2a to your computer and use it in GitHub Desktop.
Creating the session for Hibernate ORM (newer version with StandardServiceRegistryBuilder)
This file contains hidden or 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 hibernate; | |
| import org.hibernate.SessionFactory; | |
| import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | |
| import org.hibernate.cfg.Configuration; | |
| import org.hibernate.service.ServiceRegistry; | |
| public class hibernateUtils { | |
| private static SessionFactory sessionFactory; | |
| private static ServiceRegistry serviceRegistry; | |
| static | |
| { | |
| try | |
| { | |
| Configuration configuration = new Configuration().configure(); | |
| serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); | |
| sessionFactory = configuration.buildSessionFactory(serviceRegistry); | |
| } | |
| finally | |
| { | |
| } | |
| } | |
| public static SessionFactory getSessionFactory() | |
| { | |
| return sessionFactory; | |
| } | |
| } |
This file contains hidden or 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 hibernate; | |
| import org.hibernate.Session; | |
| public class ProteinTracker { | |
| public static void main(String[] args) { | |
| Session session = hibernateUtils.getSessionFactory().openSession(); | |
| session.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment