Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.psc.db;
- import com.psc.db.mapped.Part;
- import org.hibernate.HibernateException;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.cfg.Configuration;
- public class HibernateSessionHandler {
- private static final SessionFactory sessionFactory;
- static {
- try {
- sessionFactory = new Configuration().addAnnotatedClass(Part.class).configure("hibernate.cfg.xml").buildSessionFactory();
- } catch (Throwable e) {
- System.err.println("Error in creating SessionFactory object." + e.getMessage());
- throw new ExceptionInInitializerError(e);
- }
- }
- public static SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- public static Session getCurrentSession() {
- try {
- return sessionFactory.getCurrentSession();
- } catch (HibernateException he) {
- return sessionFactory.openSession();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement